blob: 1ea17981a2d88850d72c21a7048673fec0fdb9d4 [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 Smithe301ba22015-11-11 02:02:15 +0000851 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
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.
Richard Smithe301ba22015-11-11 02:02:15 +0000855 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000856 /*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
Richard Smith9f690bd2015-10-27 06:02:45 +00001290 /// \brief Build a new co_return statement.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1295 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1296 }
1297
1298 /// \brief Build a new co_await expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1303 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1304 }
1305
1306 /// \brief Build a new co_yield expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1311 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1312 }
1313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +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 RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001320 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001322 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001323 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001324 }
1325
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001326 /// \brief Rebuild an Objective-C exception declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new declaration.
1329 /// Subclasses may override this routine to provide different behavior.
1330 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1331 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001332 return getSema().BuildObjCExceptionDecl(TInfo, T,
1333 ExceptionDecl->getInnerLocStart(),
1334 ExceptionDecl->getLocation(),
1335 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001337
James Dennett2a4d13c2012-06-15 07:13:21 +00001338 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001343 SourceLocation RParenLoc,
1344 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001345 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001346 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001347 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001355 Stmt *Body) {
1356 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001358
James Dennett2a4d13c2012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Expr *Operand) {
1365 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001367
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001368 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001372 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001373 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001374 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001375 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001376 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001377 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001378 return getSema().ActOnOpenMPExecutableDirective(
1379 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 }
1381
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001382 /// \brief Build a new OpenMP 'if' clause.
1383 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001384 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001385 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001386 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1387 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001388 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389 SourceLocation NameModifierLoc,
1390 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001391 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1393 LParenLoc, NameModifierLoc, ColonLoc,
1394 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001395 }
1396
Alexey Bataev3778b602014-07-17 07:32:53 +00001397 /// \brief Build a new OpenMP 'final' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1402 SourceLocation LParenLoc,
1403 SourceLocation EndLoc) {
1404 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1405 EndLoc);
1406 }
1407
Alexey Bataev568a8332014-03-06 06:15:19 +00001408 /// \brief Build a new OpenMP 'num_threads' clause.
1409 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001410 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1413 SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1417 LParenLoc, EndLoc);
1418 }
1419
Alexey Bataev62c87d22014-03-21 04:51:18 +00001420 /// \brief Build a new OpenMP 'safelen' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1428 }
1429
Alexey Bataev66b15b52015-08-21 11:14:16 +00001430 /// \brief Build a new OpenMP 'simdlen' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexander Musman8bd31e62014-05-27 15:12:19 +00001440 /// \brief Build a new OpenMP 'collapse' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1445 SourceLocation LParenLoc,
1446 SourceLocation EndLoc) {
1447 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1448 EndLoc);
1449 }
1450
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001451 /// \brief Build a new OpenMP 'default' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1456 SourceLocation KindKwLoc,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1461 StartLoc, LParenLoc, EndLoc);
1462 }
1463
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001464 /// \brief Build a new OpenMP 'proc_bind' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001467 /// Subclasses may override this routine to provide different behavior.
1468 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1469 SourceLocation KindKwLoc,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1474 StartLoc, LParenLoc, EndLoc);
1475 }
1476
Alexey Bataev56dafe82014-06-20 07:16:17 +00001477 /// \brief Build a new OpenMP 'schedule' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new OpenMP clause.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1482 Expr *ChunkSize,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation KindLoc,
1486 SourceLocation CommaLoc,
1487 SourceLocation EndLoc) {
1488 return getSema().ActOnOpenMPScheduleClause(
1489 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1490 }
1491
Alexey Bataev10e775f2015-07-30 11:36:16 +00001492 /// \brief Build a new OpenMP 'ordered' clause.
1493 ///
1494 /// By default, performs semantic analysis to build the new OpenMP clause.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1497 SourceLocation EndLoc,
1498 SourceLocation LParenLoc, Expr *Num) {
1499 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1500 }
1501
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001502 /// \brief Build a new OpenMP 'private' clause.
1503 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001504 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001514 /// \brief Build a new OpenMP 'firstprivate' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001517 /// Subclasses may override this routine to provide different behavior.
1518 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexander Musman1bb328c2014-06-04 13:06:39 +00001526 /// \brief Build a new OpenMP 'lastprivate' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new OpenMP clause.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation EndLoc) {
1534 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1535 EndLoc);
1536 }
1537
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001538 /// \brief Build a new OpenMP 'shared' clause.
1539 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001540 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001541 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001542 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1543 SourceLocation StartLoc,
1544 SourceLocation LParenLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1547 EndLoc);
1548 }
1549
Alexey Bataevc5e02582014-06-16 07:08:35 +00001550 /// \brief Build a new OpenMP 'reduction' clause.
1551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1555 SourceLocation StartLoc,
1556 SourceLocation LParenLoc,
1557 SourceLocation ColonLoc,
1558 SourceLocation EndLoc,
1559 CXXScopeSpec &ReductionIdScopeSpec,
1560 const DeclarationNameInfo &ReductionId) {
1561 return getSema().ActOnOpenMPReductionClause(
1562 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1563 ReductionId);
1564 }
1565
Alexander Musman8dba6642014-04-22 13:09:42 +00001566 /// \brief Build a new OpenMP 'linear' clause.
1567 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001568 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001569 /// Subclasses may override this routine to provide different behavior.
1570 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1571 SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001573 OpenMPLinearClauseKind Modifier,
1574 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001575 SourceLocation ColonLoc,
1576 SourceLocation EndLoc) {
1577 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001578 Modifier, ModifierLoc, ColonLoc,
1579 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 }
1581
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001582 /// \brief Build a new OpenMP 'aligned' clause.
1583 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001584 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001585 /// Subclasses may override this routine to provide different behavior.
1586 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1587 SourceLocation StartLoc,
1588 SourceLocation LParenLoc,
1589 SourceLocation ColonLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1592 LParenLoc, ColonLoc, EndLoc);
1593 }
1594
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001595 /// \brief Build a new OpenMP 'copyin' clause.
1596 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001597 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataevbae9a792014-06-27 10:37:06 +00001607 /// \brief Build a new OpenMP 'copyprivate' 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 *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataev6125da92014-07-21 11:26:11 +00001619 /// \brief Build a new OpenMP 'flush' pseudo clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001631 /// \brief Build a new OpenMP 'depend' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *
1636 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1637 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1638 SourceLocation StartLoc, SourceLocation LParenLoc,
1639 SourceLocation EndLoc) {
1640 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1641 StartLoc, LParenLoc, EndLoc);
1642 }
1643
Michael Wonge710d542015-08-07 16:16:36 +00001644 /// \brief Build a new OpenMP 'device' clause.
1645 ///
1646 /// By default, performs semantic analysis to build the new statement.
1647 /// Subclasses may override this routine to provide different behavior.
1648 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1649 SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001651 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001652 EndLoc);
1653 }
1654
Kelvin Li0bff7af2015-11-23 05:32:03 +00001655 /// \brief Build a new OpenMP 'map' clause.
1656 ///
1657 /// By default, performs semantic analysis to build the new OpenMP clause.
1658 /// Subclasses may override this routine to provide different behavior.
1659 OMPClause *RebuildOMPMapClause(
1660 OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1661 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1662 SourceLocation StartLoc, SourceLocation LParenLoc,
1663 SourceLocation EndLoc) {
1664 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1665 ColonLoc, VarList,StartLoc,
1666 LParenLoc, EndLoc);
1667 }
1668
Kelvin Li099bb8c2015-11-24 20:50:12 +00001669 /// \brief Build a new OpenMP 'num_teams' clause.
1670 ///
1671 /// By default, performs semantic analysis to build the new statement.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1674 SourceLocation LParenLoc,
1675 SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1677 EndLoc);
1678 }
1679
James Dennett2a4d13c2012-06-15 07:13:21 +00001680 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001681 ///
1682 /// By default, performs semantic analysis to build the new statement.
1683 /// Subclasses may override this routine to provide different behavior.
1684 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1685 Expr *object) {
1686 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1687 }
1688
James Dennett2a4d13c2012-06-15 07:13:21 +00001689 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001690 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001691 /// By default, performs semantic analysis to build the new statement.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001694 Expr *Object, Stmt *Body) {
1695 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001696 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001697
James Dennett2a4d13c2012-06-15 07:13:21 +00001698 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001699 ///
1700 /// By default, performs semantic analysis to build the new statement.
1701 /// Subclasses may override this routine to provide different behavior.
1702 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1703 Stmt *Body) {
1704 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1705 }
John McCall53848232011-07-27 01:07:15 +00001706
Douglas Gregorf68a5082010-04-22 23:10:45 +00001707 /// \brief Build a new Objective-C fast enumeration statement.
1708 ///
1709 /// By default, performs semantic analysis to build the new statement.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001712 Stmt *Element,
1713 Expr *Collection,
1714 SourceLocation RParenLoc,
1715 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001716 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001717 Element,
John McCallb268a282010-08-23 23:25:46 +00001718 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001719 RParenLoc);
1720 if (ForEachStmt.isInvalid())
1721 return StmtError();
1722
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001723 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001725
Douglas Gregorebe10102009-08-20 07:17:43 +00001726 /// \brief Build a new C++ exception declaration.
1727 ///
1728 /// By default, performs semantic analysis to build the new decaration.
1729 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001730 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001731 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001732 SourceLocation StartLoc,
1733 SourceLocation IdLoc,
1734 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001735 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001736 StartLoc, IdLoc, Id);
1737 if (Var)
1738 getSema().CurContext->addDecl(Var);
1739 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001740 }
1741
1742 /// \brief Build a new C++ catch statement.
1743 ///
1744 /// By default, performs semantic analysis to build the new statement.
1745 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001746 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001747 VarDecl *ExceptionDecl,
1748 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001749 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1750 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregorebe10102009-08-20 07:17:43 +00001753 /// \brief Build a new C++ try statement.
1754 ///
1755 /// By default, performs semantic analysis to build the new statement.
1756 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001757 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1758 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001759 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001760 }
Mike Stump11289f42009-09-09 15:08:12 +00001761
Richard Smith02e85f32011-04-14 22:09:26 +00001762 /// \brief Build a new C++0x range-based for statement.
1763 ///
1764 /// By default, performs semantic analysis to build the new statement.
1765 /// Subclasses may override this routine to provide different behavior.
1766 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001767 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001768 SourceLocation ColonLoc,
1769 Stmt *Range, Stmt *BeginEnd,
1770 Expr *Cond, Expr *Inc,
1771 Stmt *LoopVar,
1772 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001773 // If we've just learned that the range is actually an Objective-C
1774 // collection, treat this as an Objective-C fast enumeration loop.
1775 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1776 if (RangeStmt->isSingleDecl()) {
1777 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001778 if (RangeVar->isInvalidDecl())
1779 return StmtError();
1780
Douglas Gregorf7106af2013-04-08 18:40:13 +00001781 Expr *RangeExpr = RangeVar->getInit();
1782 if (!RangeExpr->isTypeDependent() &&
1783 RangeExpr->getType()->isObjCObjectPointerType())
1784 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1785 RParenLoc);
1786 }
1787 }
1788 }
1789
Richard Smithcfd53b42015-10-22 06:13:50 +00001790 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1791 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001792 Cond, Inc, LoopVar, RParenLoc,
1793 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001794 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001795
1796 /// \brief Build a new C++0x range-based for statement.
1797 ///
1798 /// By default, performs semantic analysis to build the new statement.
1799 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001800 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001801 bool IsIfExists,
1802 NestedNameSpecifierLoc QualifierLoc,
1803 DeclarationNameInfo NameInfo,
1804 Stmt *Nested) {
1805 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1806 QualifierLoc, NameInfo, Nested);
1807 }
1808
Richard Smith02e85f32011-04-14 22:09:26 +00001809 /// \brief Attach body to a C++0x range-based for statement.
1810 ///
1811 /// By default, performs semantic analysis to finish the new statement.
1812 /// Subclasses may override this routine to provide different behavior.
1813 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1814 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001816
David Majnemerfad8f482013-10-15 09:33:02 +00001817 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001818 Stmt *TryBlock, Stmt *Handler) {
1819 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001820 }
1821
David Majnemerfad8f482013-10-15 09:33:02 +00001822 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001823 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001824 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001825 }
1826
David Majnemerfad8f482013-10-15 09:33:02 +00001827 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001828 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001829 }
1830
Alexey Bataevec474782014-10-09 08:45:04 +00001831 /// \brief Build a new predefined expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
1835 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1836 PredefinedExpr::IdentType IT) {
1837 return getSema().BuildPredefinedExpr(Loc, IT);
1838 }
1839
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// \brief Build a new expression that references a declaration.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001845 LookupResult &R,
1846 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001847 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1848 }
1849
1850
1851 /// \brief Build a new expression that references a declaration.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001855 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001856 ValueDecl *VD,
1857 const DeclarationNameInfo &NameInfo,
1858 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001859 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001860 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001861
1862 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001863
1864 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 }
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001868 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001871 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001873 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 }
1875
Douglas Gregorad8a3362009-09-04 17:36:40 +00001876 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001877 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001881 SourceLocation OperatorLoc,
1882 bool isArrow,
1883 CXXScopeSpec &SS,
1884 TypeSourceInfo *ScopeType,
1885 SourceLocation CCLoc,
1886 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001887 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001890 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001894 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001895 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001896 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregor882211c2010-04-28 22:16:22 +00001899 /// \brief Build a new builtin offsetof expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001903 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001904 TypeSourceInfo *Type,
1905 ArrayRef<Sema::OffsetOfComponent> Components,
1906 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001907 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001908 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001909 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001910
1911 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001912 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001916 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1917 SourceLocation OpLoc,
1918 UnaryExprOrTypeTrait ExprKind,
1919 SourceRange R) {
1920 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 }
1922
Peter Collingbournee190dee2011-03-11 19:24:49 +00001923 /// \brief Build a new sizeof, alignof or vec step expression with an
1924 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001925 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001928 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1929 UnaryExprOrTypeTrait ExprKind,
1930 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001932 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001935
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001936 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001945 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001947 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001948 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 RBracketLoc);
1950 }
1951
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001952 /// \brief Build a new array section expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
1956 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1957 Expr *LowerBound,
1958 SourceLocation ColonLoc, Expr *Length,
1959 SourceLocation RBracketLoc) {
1960 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1961 ColonLoc, Length, RBracketLoc);
1962 }
1963
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001965 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001970 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001971 Expr *ExecConfig = nullptr) {
1972 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001973 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
1975
1976 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001977 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001981 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001982 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001983 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001984 const DeclarationNameInfo &MemberNameInfo,
1985 ValueDecl *Member,
1986 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001987 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001988 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001989 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1990 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001991 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001992 // We have a reference to an unnamed field. This is always the
1993 // base of an anonymous struct/union member access, i.e. the
1994 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001995 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001996 assert(Member->getType()->isRecordType() &&
1997 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001998
Richard Smithcab9a7d2011-10-26 19:06:56 +00001999 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002000 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002001 QualifierLoc.getNestedNameSpecifier(),
2002 FoundDecl, Member);
2003 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002004 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002005 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002006 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002007 MemberExpr *ME = new (getSema().Context)
2008 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2009 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002010 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002011 }
Mike Stump11289f42009-09-09 15:08:12 +00002012
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002013 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002014 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002015
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002016 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002017 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002018
John McCall16df1e52010-03-30 21:47:33 +00002019 // FIXME: this involves duplicating earlier analysis in a lot of
2020 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002021 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002022 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002023 R.resolveKind();
2024
John McCallb268a282010-08-23 23:25:46 +00002025 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002026 SS, TemplateKWLoc,
2027 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002028 R, ExplicitTemplateArgs,
2029 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
Mike Stump11289f42009-09-09 15:08:12 +00002031
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002033 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002036 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002037 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002038 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002039 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
2041
2042 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002047 SourceLocation QuestionLoc,
2048 Expr *LHS,
2049 SourceLocation ColonLoc,
2050 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002051 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2052 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 }
2054
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002056 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002059 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002060 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002062 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002063 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002064 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 }
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002072 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002074 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002075 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 }
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002080 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 SourceLocation OpLoc,
2085 SourceLocation AccessorLoc,
2086 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002087
John McCall10eae182009-11-30 22:42:35 +00002088 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002089 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002090 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002091 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002092 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002093 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002094 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002095 /* TemplateArgs */ nullptr,
2096 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 }
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002104 MultiExprArg Inits,
2105 SourceLocation RBraceLoc,
2106 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002108 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002109 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002110 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002111
Douglas Gregord3d93062009-11-09 17:16:50 +00002112 // Patch in the result type we were given, which may have been computed
2113 // when the initial InitListExpr was built.
2114 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2115 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002116 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002120 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002123 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 MultiExprArg ArrayExprs,
2125 SourceLocation EqualOrColonLoc,
2126 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002127 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002130 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002133
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002134 return Result;
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 value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 /// By default, builds the implicit value initialization without performing
2140 /// any semantic analysis. Subclasses may override this routine to provide
2141 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002143 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002151 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002152 SourceLocation RParenLoc) {
2153 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002154 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002155 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
2158 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002163 MultiExprArg SubExprs,
2164 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002165 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 }
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002169 ///
2170 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// rather than attempting to map the label statement itself.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002174 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002175 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 }
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002179 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002182 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002183 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002185 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// \brief Build a new __builtin_choose_expr expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002193 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RParenLoc) {
2195 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002196 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 RParenLoc);
2198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Peter Collingbourne91147592011-04-15 00:35:48 +00002200 /// \brief Build a new generic selection expression.
2201 ///
2202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
2204 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2205 SourceLocation DefaultLoc,
2206 SourceLocation RParenLoc,
2207 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002208 ArrayRef<TypeSourceInfo *> Types,
2209 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002210 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002211 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002212 }
2213
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// \brief Build a new overloaded operator call expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// The semantic analysis provides the behavior of template instantiation,
2218 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002219 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 /// argument-dependent lookup, etc. Subclasses may override this routine to
2221 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002222 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002224 Expr *Callee,
2225 Expr *First,
2226 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002227
2228 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 /// reinterpret_cast.
2230 ///
2231 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002232 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002234 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 Stmt::StmtClass Class,
2236 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002237 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 SourceLocation RAngleLoc,
2239 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002240 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 SourceLocation RParenLoc) {
2242 switch (Class) {
2243 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002244 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002245 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002246 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247
2248 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002249 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002250 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002251 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002252
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002254 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002255 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002256 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002258
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002260 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002261 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002262 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002265 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new C++ static_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 RebuildCXXStaticCastExpr(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_static_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 }
2285
2286 /// \brief Build a new C++ dynamic_cast expression.
2287 ///
2288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002290 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002292 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 SourceLocation RAngleLoc,
2294 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002295 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002297 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002298 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002299 SourceRange(LAngleLoc, RAngleLoc),
2300 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
2302
2303 /// \brief Build a new C++ reinterpret_cast expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002309 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 SourceLocation RAngleLoc,
2311 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002312 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002314 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002315 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002316 SourceRange(LAngleLoc, RAngleLoc),
2317 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 }
2319
2320 /// \brief Build a new C++ const_cast expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002324 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002326 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 SourceLocation RAngleLoc,
2328 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002329 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002331 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002332 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002333 SourceRange(LAngleLoc, RAngleLoc),
2334 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new C++ functional-style cast expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002341 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2342 SourceLocation LParenLoc,
2343 Expr *Sub,
2344 SourceLocation RParenLoc) {
2345 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002346 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 RParenLoc);
2348 }
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 /// \brief Build a new C++ typeid(type) expression.
2351 ///
2352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002355 SourceLocation TypeidLoc,
2356 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002358 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002359 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 }
Mike Stump11289f42009-09-09 15:08:12 +00002361
Francois Pichet9f4f2072010-09-08 12:20:18 +00002362
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 /// \brief Build a new C++ typeid(expr) expression.
2364 ///
2365 /// By default, performs semantic analysis to build the new expression.
2366 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002367 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002368 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002369 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002371 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002372 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002373 }
2374
Francois Pichet9f4f2072010-09-08 12:20:18 +00002375 /// \brief Build a new C++ __uuidof(type) expression.
2376 ///
2377 /// By default, performs semantic analysis to build the new expression.
2378 /// Subclasses may override this routine to provide different behavior.
2379 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2380 SourceLocation TypeidLoc,
2381 TypeSourceInfo *Operand,
2382 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002383 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002384 RParenLoc);
2385 }
2386
2387 /// \brief Build a new C++ __uuidof(expr) expression.
2388 ///
2389 /// By default, performs semantic analysis to build the new expression.
2390 /// Subclasses may override this routine to provide different behavior.
2391 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2392 SourceLocation TypeidLoc,
2393 Expr *Operand,
2394 SourceLocation RParenLoc) {
2395 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2396 RParenLoc);
2397 }
2398
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 /// \brief Build a new C++ "this" expression.
2400 ///
2401 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002402 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002404 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002405 QualType ThisType,
2406 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002407 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002408 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 }
2410
2411 /// \brief Build a new C++ throw expression.
2412 ///
2413 /// By default, performs semantic analysis to build the new expression.
2414 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002415 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2416 bool IsThrownVariableInScope) {
2417 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 }
2419
2420 /// \brief Build a new C++ default-argument expression.
2421 ///
2422 /// By default, builds a new default-argument expression, which does not
2423 /// require any semantic analysis. Subclasses may override this routine to
2424 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002425 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002426 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002427 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 }
2429
Richard Smith852c9db2013-04-20 22:23:05 +00002430 /// \brief Build a new C++11 default-initialization expression.
2431 ///
2432 /// By default, builds a new default field initialization expression, which
2433 /// does not require any semantic analysis. Subclasses may override this
2434 /// routine to provide different behavior.
2435 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2436 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002437 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002438 }
2439
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// \brief Build a new C++ zero-initialization expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002444 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2445 SourceLocation LParenLoc,
2446 SourceLocation RParenLoc) {
2447 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002448 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 }
Mike Stump11289f42009-09-09 15:08:12 +00002450
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 /// \brief Build a new C++ "new" expression.
2452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002455 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002456 bool UseGlobal,
2457 SourceLocation PlacementLParen,
2458 MultiExprArg PlacementArgs,
2459 SourceLocation PlacementRParen,
2460 SourceRange TypeIdParens,
2461 QualType AllocatedType,
2462 TypeSourceInfo *AllocatedTypeInfo,
2463 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002464 SourceRange DirectInitRange,
2465 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002466 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002468 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002470 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002471 AllocatedType,
2472 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002473 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002474 DirectInitRange,
2475 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 }
Mike Stump11289f42009-09-09 15:08:12 +00002477
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 /// \brief Build a new C++ "delete" expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002482 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 bool IsGlobalDelete,
2484 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002485 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002487 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregor29c42f22012-02-24 07:38:34 +00002490 /// \brief Build a new type trait expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildTypeTrait(TypeTrait Trait,
2495 SourceLocation StartLoc,
2496 ArrayRef<TypeSourceInfo *> Args,
2497 SourceLocation RParenLoc) {
2498 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002500
John Wiegley6242b6a2011-04-28 00:16:57 +00002501 /// \brief Build a new array type trait expression.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
2505 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2506 SourceLocation StartLoc,
2507 TypeSourceInfo *TSInfo,
2508 Expr *DimExpr,
2509 SourceLocation RParenLoc) {
2510 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2511 }
2512
John Wiegleyf9f65842011-04-25 06:54:41 +00002513 /// \brief Build a new expression trait expression.
2514 ///
2515 /// By default, performs semantic analysis to build the new expression.
2516 /// Subclasses may override this routine to provide different behavior.
2517 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2518 SourceLocation StartLoc,
2519 Expr *Queried,
2520 SourceLocation RParenLoc) {
2521 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2522 }
2523
Mike Stump11289f42009-09-09 15:08:12 +00002524 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 /// expression.
2526 ///
2527 /// By default, performs semantic analysis to build the new expression.
2528 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002529 ExprResult RebuildDependentScopeDeclRefExpr(
2530 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002531 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002532 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002533 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002534 bool IsAddressOfOperand,
2535 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002537 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002538
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002539 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002540 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2541 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002542
Reid Kleckner32506ed2014-06-12 23:03:48 +00002543 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002544 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 }
2546
2547 /// \brief Build a new template-id expression.
2548 ///
2549 /// By default, performs semantic analysis to build the new expression.
2550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002551 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002552 SourceLocation TemplateKWLoc,
2553 LookupResult &R,
2554 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002555 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002556 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2557 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 }
2559
2560 /// \brief Build a new object-construction expression.
2561 ///
2562 /// By default, performs semantic analysis to build the new expression.
2563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002564 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002565 SourceLocation Loc,
2566 CXXConstructorDecl *Constructor,
2567 bool IsElidable,
2568 MultiExprArg Args,
2569 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002570 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002571 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002572 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002573 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002574 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002575 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002576 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002577 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002578 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002579
Douglas Gregordb121ba2009-12-14 16:27:04 +00002580 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002581 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002582 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002583 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002584 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002585 RequiresZeroInit, ConstructKind,
2586 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 }
2588
2589 /// \brief Build a new object-construction expression.
2590 ///
2591 /// By default, performs semantic analysis to build the new expression.
2592 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002593 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2594 SourceLocation LParenLoc,
2595 MultiExprArg Args,
2596 SourceLocation RParenLoc) {
2597 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002599 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 RParenLoc);
2601 }
2602
2603 /// \brief Build a new object-construction expression.
2604 ///
2605 /// By default, performs semantic analysis to build the new expression.
2606 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002607 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2608 SourceLocation LParenLoc,
2609 MultiExprArg Args,
2610 SourceLocation RParenLoc) {
2611 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002613 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 RParenLoc);
2615 }
Mike Stump11289f42009-09-09 15:08:12 +00002616
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 /// \brief Build a new member reference expression.
2618 ///
2619 /// By default, performs semantic analysis to build the new expression.
2620 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002621 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002622 QualType BaseType,
2623 bool IsArrow,
2624 SourceLocation OperatorLoc,
2625 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002626 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002627 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002628 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002629 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002630 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002631 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002632
John McCallb268a282010-08-23 23:25:46 +00002633 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002634 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002635 SS, TemplateKWLoc,
2636 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002637 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002638 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 }
2640
John McCall10eae182009-11-30 22:42:35 +00002641 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002645 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2646 SourceLocation OperatorLoc,
2647 bool IsArrow,
2648 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002649 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002650 NamedDecl *FirstQualifierInScope,
2651 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002652 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002653 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002654 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002655
John McCallb268a282010-08-23 23:25:46 +00002656 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002657 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002658 SS, TemplateKWLoc,
2659 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002660 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002661 }
Mike Stump11289f42009-09-09 15:08:12 +00002662
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002663 /// \brief Build a new noexcept expression.
2664 ///
2665 /// By default, performs semantic analysis to build the new expression.
2666 /// Subclasses may override this routine to provide different behavior.
2667 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2668 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2669 }
2670
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002671 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002672 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2673 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002674 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002675 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002676 Optional<unsigned> Length,
2677 ArrayRef<TemplateArgument> PartialArgs) {
2678 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2679 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002680 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002681
Patrick Beard0caa3942012-04-19 00:25:12 +00002682 /// \brief Build a new Objective-C boxed expression.
2683 ///
2684 /// By default, performs semantic analysis to build the new expression.
2685 /// Subclasses may override this routine to provide different behavior.
2686 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2687 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002689
Ted Kremeneke65b0862012-03-06 20:05:56 +00002690 /// \brief Build a new Objective-C array literal.
2691 ///
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2694 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2695 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002696 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002697 MultiExprArg(Elements, NumElements));
2698 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002699
2700 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002701 Expr *Base, Expr *Key,
2702 ObjCMethodDecl *getterMethod,
2703 ObjCMethodDecl *setterMethod) {
2704 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2705 getterMethod, setterMethod);
2706 }
2707
2708 /// \brief Build a new Objective-C dictionary literal.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2712 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2713 ObjCDictionaryElement *Elements,
2714 unsigned NumElements) {
2715 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002717
James Dennett2a4d13c2012-06-15 07:13:21 +00002718 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002722 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002723 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002724 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002725 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002726 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002727
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002728 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002729 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002730 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002731 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002732 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002733 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002734 MultiExprArg Args,
2735 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002736 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2737 ReceiverTypeInfo->getType(),
2738 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002739 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002740 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002741 }
2742
2743 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002744 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002745 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002746 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002747 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002748 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002749 MultiExprArg Args,
2750 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002751 return SemaRef.BuildInstanceMessage(Receiver,
2752 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002753 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002754 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002755 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002756 }
2757
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002758 /// \brief Build a new Objective-C instance/class message to 'super'.
2759 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2760 Selector Sel,
2761 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002762 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002763 ObjCMethodDecl *Method,
2764 SourceLocation LBracLoc,
2765 MultiExprArg Args,
2766 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002767 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002768 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002769 SuperLoc,
2770 Sel, Method, LBracLoc, SelectorLocs,
2771 RBracLoc, Args)
2772 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002773 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002774 SuperLoc,
2775 Sel, Method, LBracLoc, SelectorLocs,
2776 RBracLoc, Args);
2777
2778
2779 }
2780
Douglas Gregord51d90d2010-04-26 20:11:03 +00002781 /// \brief Build a new Objective-C ivar reference expression.
2782 ///
2783 /// By default, performs semantic analysis to build the new expression.
2784 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002785 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002786 SourceLocation IvarLoc,
2787 bool IsArrow, bool IsFreeIvar) {
2788 // FIXME: We lose track of the IsFreeIvar bit.
2789 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002790 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2791 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002792 /*FIXME:*/IvarLoc, IsArrow,
2793 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002794 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002795 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002796 /*TemplateArgs=*/nullptr,
2797 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002798 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002799
2800 /// \brief Build a new Objective-C property reference expression.
2801 ///
2802 /// By default, performs semantic analysis to build the new expression.
2803 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002804 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002805 ObjCPropertyDecl *Property,
2806 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002807 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002808 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2809 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2810 /*FIXME:*/PropertyLoc,
2811 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002812 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002813 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002814 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002815 /*TemplateArgs=*/nullptr,
2816 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002818
John McCallb7bd14f2010-12-02 01:19:52 +00002819 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002820 ///
2821 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002822 /// Subclasses may override this routine to provide different behavior.
2823 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2824 ObjCMethodDecl *Getter,
2825 ObjCMethodDecl *Setter,
2826 SourceLocation PropertyLoc) {
2827 // Since these expressions can only be value-dependent, we do not
2828 // need to perform semantic analysis again.
2829 return Owned(
2830 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2831 VK_LValue, OK_ObjCProperty,
2832 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002833 }
2834
Douglas Gregord51d90d2010-04-26 20:11:03 +00002835 /// \brief Build a new Objective-C "isa" expression.
2836 ///
2837 /// By default, performs semantic analysis to build the new expression.
2838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002839 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002840 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002841 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002842 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2843 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002844 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002845 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002846 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002847 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002848 /*TemplateArgs=*/nullptr,
2849 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002851
Douglas Gregora16548e2009-08-11 05:31:07 +00002852 /// \brief Build a new shuffle vector expression.
2853 ///
2854 /// By default, performs semantic analysis to build the new expression.
2855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002856 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002857 MultiExprArg SubExprs,
2858 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002859 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002860 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002861 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2862 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2863 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002864 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002865
Douglas Gregora16548e2009-08-11 05:31:07 +00002866 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002867 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002868 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2869 SemaRef.Context.BuiltinFnTy,
2870 VK_RValue, BuiltinLoc);
2871 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2872 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002873 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002874
2875 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002876 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002877 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002878 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002879
Douglas Gregora16548e2009-08-11 05:31:07 +00002880 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002881 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002882 }
John McCall31f82722010-11-12 08:19:04 +00002883
Hal Finkelc4d7c822013-09-18 03:29:45 +00002884 /// \brief Build a new convert vector expression.
2885 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2886 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2887 SourceLocation RParenLoc) {
2888 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2889 BuiltinLoc, RParenLoc);
2890 }
2891
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002892 /// \brief Build a new template argument pack expansion.
2893 ///
2894 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002895 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002896 /// different behavior.
2897 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002898 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002899 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002900 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002901 case TemplateArgument::Expression: {
2902 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002903 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2904 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002905 if (Result.isInvalid())
2906 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002907
Douglas Gregor98318c22011-01-03 21:37:45 +00002908 return TemplateArgumentLoc(Result.get(), Result.get());
2909 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002910
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002911 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002912 return TemplateArgumentLoc(TemplateArgument(
2913 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002914 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002915 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002916 Pattern.getTemplateNameLoc(),
2917 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002918
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002919 case TemplateArgument::Null:
2920 case TemplateArgument::Integral:
2921 case TemplateArgument::Declaration:
2922 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002923 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002924 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002925 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002927 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002928 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002929 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002930 EllipsisLoc,
2931 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002932 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2933 Expansion);
2934 break;
2935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 return TemplateArgumentLoc();
2938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
Douglas Gregor968f23a2011-01-03 19:31:53 +00002940 /// \brief Build a new expression pack expansion.
2941 ///
2942 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002943 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002944 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002945 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002946 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002947 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002948 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002949
Richard Smith0f0af192014-11-08 05:07:16 +00002950 /// \brief Build a new C++1z fold-expression.
2951 ///
2952 /// By default, performs semantic analysis in order to build a new fold
2953 /// expression.
2954 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2955 BinaryOperatorKind Operator,
2956 SourceLocation EllipsisLoc, Expr *RHS,
2957 SourceLocation RParenLoc) {
2958 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2959 RHS, RParenLoc);
2960 }
2961
2962 /// \brief Build an empty C++1z fold-expression with the given operator.
2963 ///
2964 /// By default, produces the fallback value for the fold-expression, or
2965 /// produce an error if there is no fallback value.
2966 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2967 BinaryOperatorKind Operator) {
2968 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2969 }
2970
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002971 /// \brief Build a new atomic operation expression.
2972 ///
2973 /// By default, performs semantic analysis to build the new expression.
2974 /// Subclasses may override this routine to provide different behavior.
2975 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2976 MultiExprArg SubExprs,
2977 QualType RetTy,
2978 AtomicExpr::AtomicOp Op,
2979 SourceLocation RParenLoc) {
2980 // Just create the expression; there is not any interesting semantic
2981 // analysis here because we can't actually build an AtomicExpr until
2982 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002983 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002984 RParenLoc);
2985 }
2986
John McCall31f82722010-11-12 08:19:04 +00002987private:
Douglas Gregor14454802011-02-25 02:25:35 +00002988 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2989 QualType ObjectType,
2990 NamedDecl *FirstQualifierInScope,
2991 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002992
2993 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2994 QualType ObjectType,
2995 NamedDecl *FirstQualifierInScope,
2996 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002997
2998 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2999 NamedDecl *FirstQualifierInScope,
3000 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003001};
Douglas Gregora16548e2009-08-11 05:31:07 +00003002
Douglas Gregorebe10102009-08-20 07:17:43 +00003003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003004StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003005 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003006 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003007
Douglas Gregorebe10102009-08-20 07:17:43 +00003008 switch (S->getStmtClass()) {
3009 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003010
Douglas Gregorebe10102009-08-20 07:17:43 +00003011 // Transform individual statement nodes
3012#define STMT(Node, Parent) \
3013 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003014#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003015#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003016#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregorebe10102009-08-20 07:17:43 +00003018 // Transform expressions by calling TransformExpr.
3019#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003020#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003021#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003022#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003023 {
John McCalldadc5752010-08-24 06:29:42 +00003024 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003025 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003026 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003027
Richard Smith945f8d32013-01-14 22:39:08 +00003028 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003029 }
Mike Stump11289f42009-09-09 15:08:12 +00003030 }
3031
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003032 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003033}
Mike Stump11289f42009-09-09 15:08:12 +00003034
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003035template<typename Derived>
3036OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3037 if (!S)
3038 return S;
3039
3040 switch (S->getClauseKind()) {
3041 default: break;
3042 // Transform individual clause nodes
3043#define OPENMP_CLAUSE(Name, Class) \
3044 case OMPC_ ## Name : \
3045 return getDerived().Transform ## Class(cast<Class>(S));
3046#include "clang/Basic/OpenMPKinds.def"
3047 }
3048
3049 return S;
3050}
3051
Mike Stump11289f42009-09-09 15:08:12 +00003052
Douglas Gregore922c772009-08-04 22:27:00 +00003053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003054ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003055 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003056 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003057
3058 switch (E->getStmtClass()) {
3059 case Stmt::NoStmtClass: break;
3060#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003061#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003062#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003063 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003064#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003065 }
3066
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003067 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003068}
3069
3070template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003071ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003072 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003073 // Initializers are instantiated like expressions, except that various outer
3074 // layers are stripped.
3075 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003076 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003077
3078 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3079 Init = ExprTemp->getSubExpr();
3080
Richard Smithe6ca4752013-05-30 22:40:16 +00003081 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3082 Init = MTE->GetTemporaryExpr();
3083
Richard Smithd59b8322012-12-19 01:39:02 +00003084 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3085 Init = Binder->getSubExpr();
3086
3087 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3088 Init = ICE->getSubExprAsWritten();
3089
Richard Smithcc1b96d2013-06-12 22:31:48 +00003090 if (CXXStdInitializerListExpr *ILE =
3091 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003092 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003093
Richard Smithc6abd962014-07-25 01:12:44 +00003094 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003095 // InitListExprs. Other forms of copy-initialization will be a no-op if
3096 // the initializer is already the right type.
3097 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003098 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003099 return getDerived().TransformExpr(Init);
3100
3101 // Revert value-initialization back to empty parens.
3102 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3103 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003104 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003105 Parens.getEnd());
3106 }
3107
3108 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3109 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003110 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003111 SourceLocation());
3112
3113 // Revert initialization by constructor back to a parenthesized or braced list
3114 // of expressions. Any other form of initializer can just be reused directly.
3115 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003116 return getDerived().TransformExpr(Init);
3117
Richard Smithf8adcdc2014-07-17 05:12:35 +00003118 // If the initialization implicitly converted an initializer list to a
3119 // std::initializer_list object, unwrap the std::initializer_list too.
3120 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003121 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003122
Richard Smithd59b8322012-12-19 01:39:02 +00003123 SmallVector<Expr*, 8> NewArgs;
3124 bool ArgChanged = false;
3125 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003126 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003127 return ExprError();
3128
3129 // If this was list initialization, revert to list form.
3130 if (Construct->isListInitialization())
3131 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3132 Construct->getLocEnd(),
3133 Construct->getType());
3134
Richard Smithd59b8322012-12-19 01:39:02 +00003135 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003136 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003137 if (Parens.isInvalid()) {
3138 // This was a variable declaration's initialization for which no initializer
3139 // was specified.
3140 assert(NewArgs.empty() &&
3141 "no parens or braces but have direct init with arguments?");
3142 return ExprEmpty();
3143 }
Richard Smithd59b8322012-12-19 01:39:02 +00003144 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3145 Parens.getEnd());
3146}
3147
3148template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003149bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3150 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003151 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003152 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003153 bool *ArgChanged) {
3154 for (unsigned I = 0; I != NumInputs; ++I) {
3155 // If requested, drop call arguments that need to be dropped.
3156 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3157 if (ArgChanged)
3158 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003159
Douglas Gregora3efea12011-01-03 19:04:46 +00003160 break;
3161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor968f23a2011-01-03 19:31:53 +00003163 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3164 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003165
Chris Lattner01cf8db2011-07-20 06:58:45 +00003166 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003167 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3168 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor968f23a2011-01-03 19:31:53 +00003170 // Determine whether the set of unexpanded parameter packs can and should
3171 // be expanded.
3172 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003173 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003174 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3175 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003176 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3177 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003178 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003179 Expand, RetainExpansion,
3180 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003181 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor968f23a2011-01-03 19:31:53 +00003183 if (!Expand) {
3184 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003185 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003186 // expansion.
3187 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3188 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3189 if (OutPattern.isInvalid())
3190 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
3192 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003193 Expansion->getEllipsisLoc(),
3194 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003195 if (Out.isInvalid())
3196 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor968f23a2011-01-03 19:31:53 +00003198 if (ArgChanged)
3199 *ArgChanged = true;
3200 Outputs.push_back(Out.get());
3201 continue;
3202 }
John McCall542e7c62011-07-06 07:30:07 +00003203
3204 // Record right away that the argument was changed. This needs
3205 // to happen even if the array expands to nothing.
3206 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor968f23a2011-01-03 19:31:53 +00003208 // The transform has determined that we should perform an elementwise
3209 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3212 ExprResult Out = getDerived().TransformExpr(Pattern);
3213 if (Out.isInvalid())
3214 return true;
3215
Richard Smith9467be42014-06-06 17:33:35 +00003216 // FIXME: Can this happen? We should not try to expand the pack
3217 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003218 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003219 Out = getDerived().RebuildPackExpansion(
3220 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003221 if (Out.isInvalid())
3222 return true;
3223 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003224
Douglas Gregor968f23a2011-01-03 19:31:53 +00003225 Outputs.push_back(Out.get());
3226 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
Richard Smith9467be42014-06-06 17:33:35 +00003228 // If we're supposed to retain a pack expansion, do so by temporarily
3229 // forgetting the partially-substituted parameter pack.
3230 if (RetainExpansion) {
3231 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3232
3233 ExprResult Out = getDerived().TransformExpr(Pattern);
3234 if (Out.isInvalid())
3235 return true;
3236
3237 Out = getDerived().RebuildPackExpansion(
3238 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3239 if (Out.isInvalid())
3240 return true;
3241
3242 Outputs.push_back(Out.get());
3243 }
3244
Douglas Gregor968f23a2011-01-03 19:31:53 +00003245 continue;
3246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Richard Smithd59b8322012-12-19 01:39:02 +00003248 ExprResult Result =
3249 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3250 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003251 if (Result.isInvalid())
3252 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregora3efea12011-01-03 19:04:46 +00003254 if (Result.get() != Inputs[I] && ArgChanged)
3255 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003256
3257 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregora3efea12011-01-03 19:04:46 +00003260 return false;
3261}
3262
3263template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003264NestedNameSpecifierLoc
3265TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3266 NestedNameSpecifierLoc NNS,
3267 QualType ObjectType,
3268 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003269 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003270 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003271 Qualifier = Qualifier.getPrefix())
3272 Qualifiers.push_back(Qualifier);
3273
3274 CXXScopeSpec SS;
3275 while (!Qualifiers.empty()) {
3276 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3277 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003278
Douglas Gregor14454802011-02-25 02:25:35 +00003279 switch (QNNS->getKind()) {
3280 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003281 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003282 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003283 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003284 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003285 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003286 FirstQualifierInScope, false))
3287 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
Douglas Gregor14454802011-02-25 02:25:35 +00003289 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003290
Douglas Gregor14454802011-02-25 02:25:35 +00003291 case NestedNameSpecifier::Namespace: {
3292 NamespaceDecl *NS
3293 = cast_or_null<NamespaceDecl>(
3294 getDerived().TransformDecl(
3295 Q.getLocalBeginLoc(),
3296 QNNS->getAsNamespace()));
3297 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3298 break;
3299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor14454802011-02-25 02:25:35 +00003301 case NestedNameSpecifier::NamespaceAlias: {
3302 NamespaceAliasDecl *Alias
3303 = cast_or_null<NamespaceAliasDecl>(
3304 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3305 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003306 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003307 Q.getLocalEndLoc());
3308 break;
3309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor14454802011-02-25 02:25:35 +00003311 case NestedNameSpecifier::Global:
3312 // There is no meaningful transformation that one could perform on the
3313 // global scope.
3314 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3315 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Nikola Smiljanic67860242014-09-26 00:28:20 +00003317 case NestedNameSpecifier::Super: {
3318 CXXRecordDecl *RD =
3319 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3320 SourceLocation(), QNNS->getAsRecordDecl()));
3321 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3322 break;
3323 }
3324
Douglas Gregor14454802011-02-25 02:25:35 +00003325 case NestedNameSpecifier::TypeSpecWithTemplate:
3326 case NestedNameSpecifier::TypeSpec: {
3327 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3328 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
Douglas Gregor14454802011-02-25 02:25:35 +00003330 if (!TL)
3331 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
Douglas Gregor14454802011-02-25 02:25:35 +00003333 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003334 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003335 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003336 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003337 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003338 if (TL.getType()->isEnumeralType())
3339 SemaRef.Diag(TL.getBeginLoc(),
3340 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003341 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3342 Q.getLocalEndLoc());
3343 break;
3344 }
Richard Trieude756fb2011-05-07 01:36:37 +00003345 // If the nested-name-specifier is an invalid type def, don't emit an
3346 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003347 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3348 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003349 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003350 << TL.getType() << SS.getRange();
3351 }
Douglas Gregor14454802011-02-25 02:25:35 +00003352 return NestedNameSpecifierLoc();
3353 }
Douglas Gregore16af532011-02-28 18:50:33 +00003354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregore16af532011-02-28 18:50:33 +00003356 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003357 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003358 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor14454802011-02-25 02:25:35 +00003361 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003362 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003363 !getDerived().AlwaysRebuild())
3364 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003365
3366 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003367 // nested-name-specifier, do so.
3368 if (SS.location_size() == NNS.getDataLength() &&
3369 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3370 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3371
3372 // Allocate new nested-name-specifier location information.
3373 return SS.getWithLocInContext(SemaRef.Context);
3374}
3375
3376template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003377DeclarationNameInfo
3378TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003379::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003380 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003381 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003382 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003383
3384 switch (Name.getNameKind()) {
3385 case DeclarationName::Identifier:
3386 case DeclarationName::ObjCZeroArgSelector:
3387 case DeclarationName::ObjCOneArgSelector:
3388 case DeclarationName::ObjCMultiArgSelector:
3389 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003390 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003391 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003392 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003393
Douglas Gregorf816bd72009-09-03 22:13:48 +00003394 case DeclarationName::CXXConstructorName:
3395 case DeclarationName::CXXDestructorName:
3396 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003397 TypeSourceInfo *NewTInfo;
3398 CanQualType NewCanTy;
3399 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003400 NewTInfo = getDerived().TransformType(OldTInfo);
3401 if (!NewTInfo)
3402 return DeclarationNameInfo();
3403 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003404 }
3405 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003406 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003407 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003408 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003409 if (NewT.isNull())
3410 return DeclarationNameInfo();
3411 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3412 }
Mike Stump11289f42009-09-09 15:08:12 +00003413
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003414 DeclarationName NewName
3415 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3416 NewCanTy);
3417 DeclarationNameInfo NewNameInfo(NameInfo);
3418 NewNameInfo.setName(NewName);
3419 NewNameInfo.setNamedTypeInfo(NewTInfo);
3420 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003421 }
Mike Stump11289f42009-09-09 15:08:12 +00003422 }
3423
David Blaikie83d382b2011-09-23 05:06:16 +00003424 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003425}
3426
3427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003428TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003429TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3430 TemplateName Name,
3431 SourceLocation NameLoc,
3432 QualType ObjectType,
3433 NamedDecl *FirstQualifierInScope) {
3434 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3435 TemplateDecl *Template = QTN->getTemplateDecl();
3436 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor9db53502011-03-02 18:07:45 +00003438 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003439 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003440 Template));
3441 if (!TransTemplate)
3442 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
Douglas Gregor9db53502011-03-02 18:07:45 +00003444 if (!getDerived().AlwaysRebuild() &&
3445 SS.getScopeRep() == QTN->getQualifier() &&
3446 TransTemplate == Template)
3447 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003448
Douglas Gregor9db53502011-03-02 18:07:45 +00003449 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3450 TransTemplate);
3451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003452
Douglas Gregor9db53502011-03-02 18:07:45 +00003453 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3454 if (SS.getScopeRep()) {
3455 // These apply to the scope specifier, not the template.
3456 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003457 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003458 }
3459
Douglas Gregor9db53502011-03-02 18:07:45 +00003460 if (!getDerived().AlwaysRebuild() &&
3461 SS.getScopeRep() == DTN->getQualifier() &&
3462 ObjectType.isNull())
3463 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor9db53502011-03-02 18:07:45 +00003465 if (DTN->isIdentifier()) {
3466 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003467 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003468 NameLoc,
3469 ObjectType,
3470 FirstQualifierInScope);
3471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor9db53502011-03-02 18:07:45 +00003473 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3474 ObjectType);
3475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
Douglas Gregor9db53502011-03-02 18:07:45 +00003477 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3478 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003479 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003480 Template));
3481 if (!TransTemplate)
3482 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregor9db53502011-03-02 18:07:45 +00003484 if (!getDerived().AlwaysRebuild() &&
3485 TransTemplate == Template)
3486 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Douglas Gregor9db53502011-03-02 18:07:45 +00003488 return TemplateName(TransTemplate);
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor9db53502011-03-02 18:07:45 +00003491 if (SubstTemplateTemplateParmPackStorage *SubstPack
3492 = Name.getAsSubstTemplateTemplateParmPack()) {
3493 TemplateTemplateParmDecl *TransParam
3494 = cast_or_null<TemplateTemplateParmDecl>(
3495 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3496 if (!TransParam)
3497 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor9db53502011-03-02 18:07:45 +00003499 if (!getDerived().AlwaysRebuild() &&
3500 TransParam == SubstPack->getParameterPack())
3501 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003502
3503 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003504 SubstPack->getArgumentPack());
3505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregor9db53502011-03-02 18:07:45 +00003507 // These should be getting filtered out before they reach the AST.
3508 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003509}
3510
3511template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003512void TreeTransform<Derived>::InventTemplateArgumentLoc(
3513 const TemplateArgument &Arg,
3514 TemplateArgumentLoc &Output) {
3515 SourceLocation Loc = getDerived().getBaseLocation();
3516 switch (Arg.getKind()) {
3517 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003518 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003519 break;
3520
3521 case TemplateArgument::Type:
3522 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003523 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
John McCall0ad16662009-10-29 08:12:44 +00003525 break;
3526
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003527 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003528 case TemplateArgument::TemplateExpansion: {
3529 NestedNameSpecifierLocBuilder Builder;
3530 TemplateName Template = Arg.getAsTemplate();
3531 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3532 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3533 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3534 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor9d802122011-03-02 17:09:35 +00003536 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003537 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003538 Builder.getWithLocInContext(SemaRef.Context),
3539 Loc);
3540 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003541 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003542 Builder.getWithLocInContext(SemaRef.Context),
3543 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003544
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003545 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003546 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003547
John McCall0ad16662009-10-29 08:12:44 +00003548 case TemplateArgument::Expression:
3549 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3550 break;
3551
3552 case TemplateArgument::Declaration:
3553 case TemplateArgument::Integral:
3554 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003555 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003556 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003557 break;
3558 }
3559}
3560
3561template<typename Derived>
3562bool TreeTransform<Derived>::TransformTemplateArgument(
3563 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003564 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003565 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003566 switch (Arg.getKind()) {
3567 case TemplateArgument::Null:
3568 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003569 case TemplateArgument::Pack:
3570 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003571 case TemplateArgument::NullPtr:
3572 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregore922c772009-08-04 22:27:00 +00003574 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003575 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003576 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003577 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003578
3579 DI = getDerived().TransformType(DI);
3580 if (!DI) return true;
3581
3582 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3583 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003584 }
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003586 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003587 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3588 if (QualifierLoc) {
3589 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3590 if (!QualifierLoc)
3591 return true;
3592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregordf846d12011-03-02 18:46:51 +00003594 CXXScopeSpec SS;
3595 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003596 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003597 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3598 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003599 if (Template.isNull())
3600 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Douglas Gregor9d802122011-03-02 17:09:35 +00003602 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003603 Input.getTemplateNameLoc());
3604 return false;
3605 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003606
3607 case TemplateArgument::TemplateExpansion:
3608 llvm_unreachable("Caller should expand pack expansions");
3609
Douglas Gregore922c772009-08-04 22:27:00 +00003610 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003611 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003612 EnterExpressionEvaluationContext Unevaluated(
3613 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003614
John McCall0ad16662009-10-29 08:12:44 +00003615 Expr *InputExpr = Input.getSourceExpression();
3616 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3617
Chris Lattnercdb591a2011-04-25 20:37:58 +00003618 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003619 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003620 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003621 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003622 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003623 }
Douglas Gregore922c772009-08-04 22:27:00 +00003624 }
Mike Stump11289f42009-09-09 15:08:12 +00003625
Douglas Gregore922c772009-08-04 22:27:00 +00003626 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003627 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003628}
3629
Douglas Gregorfe921a72010-12-20 23:36:19 +00003630/// \brief Iterator adaptor that invents template argument location information
3631/// for each of the template arguments in its underlying iterator.
3632template<typename Derived, typename InputIterator>
3633class TemplateArgumentLocInventIterator {
3634 TreeTransform<Derived> &Self;
3635 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003636
Douglas Gregorfe921a72010-12-20 23:36:19 +00003637public:
3638 typedef TemplateArgumentLoc value_type;
3639 typedef TemplateArgumentLoc reference;
3640 typedef typename std::iterator_traits<InputIterator>::difference_type
3641 difference_type;
3642 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregorfe921a72010-12-20 23:36:19 +00003644 class pointer {
3645 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregorfe921a72010-12-20 23:36:19 +00003647 public:
3648 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003649
Douglas Gregorfe921a72010-12-20 23:36:19 +00003650 const TemplateArgumentLoc *operator->() const { return &Arg; }
3651 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003653 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregorfe921a72010-12-20 23:36:19 +00003655 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3656 InputIterator Iter)
3657 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregorfe921a72010-12-20 23:36:19 +00003659 TemplateArgumentLocInventIterator &operator++() {
3660 ++Iter;
3661 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003662 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregorfe921a72010-12-20 23:36:19 +00003664 TemplateArgumentLocInventIterator operator++(int) {
3665 TemplateArgumentLocInventIterator Old(*this);
3666 ++(*this);
3667 return Old;
3668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregorfe921a72010-12-20 23:36:19 +00003670 reference operator*() const {
3671 TemplateArgumentLoc Result;
3672 Self.InventTemplateArgumentLoc(*Iter, Result);
3673 return Result;
3674 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Douglas Gregorfe921a72010-12-20 23:36:19 +00003676 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregorfe921a72010-12-20 23:36:19 +00003678 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3679 const TemplateArgumentLocInventIterator &Y) {
3680 return X.Iter == Y.Iter;
3681 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003682
Douglas Gregorfe921a72010-12-20 23:36:19 +00003683 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3684 const TemplateArgumentLocInventIterator &Y) {
3685 return X.Iter != Y.Iter;
3686 }
3687};
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor42cafa82010-12-20 17:42:22 +00003689template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003690template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003691bool TreeTransform<Derived>::TransformTemplateArguments(
3692 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3693 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003694 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003695 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003696 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003697
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003698 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3699 // Unpack argument packs, which we translate them into separate
3700 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003701 // FIXME: We could do much better if we could guarantee that the
3702 // TemplateArgumentLocInfo for the pack expansion would be usable for
3703 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003704 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003705 TemplateArgument::pack_iterator>
3706 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003707 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003708 In.getArgument().pack_begin()),
3709 PackLocIterator(*this,
3710 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003711 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003712 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003714 continue;
3715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003717 if (In.getArgument().isPackExpansion()) {
3718 // We have a pack expansion, for which we will be substituting into
3719 // the pattern.
3720 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003721 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003722 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003723 = getSema().getTemplateArgumentPackExpansionPattern(
3724 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003725
Chris Lattner01cf8db2011-07-20 06:58:45 +00003726 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003727 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3728 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003729
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003730 // Determine whether the set of unexpanded parameter packs can and should
3731 // be expanded.
3732 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003733 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003734 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003735 if (getDerived().TryExpandParameterPacks(Ellipsis,
3736 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003737 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003738 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003739 RetainExpansion,
3740 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003741 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003742
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003743 if (!Expand) {
3744 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003745 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003746 // expansion.
3747 TemplateArgumentLoc OutPattern;
3748 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003749 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003750 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003751
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003752 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3753 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003754 if (Out.getArgument().isNull())
3755 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003756
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003757 Outputs.addArgument(Out);
3758 continue;
3759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003761 // The transform has determined that we should perform an elementwise
3762 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003763 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003764 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3765
Richard Smithd784e682015-09-23 21:41:42 +00003766 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003767 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003768
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003769 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003770 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3771 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003772 if (Out.getArgument().isNull())
3773 return true;
3774 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003775
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003776 Outputs.addArgument(Out);
3777 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
Douglas Gregor48d24112011-01-10 20:53:55 +00003779 // If we're supposed to retain a pack expansion, do so by temporarily
3780 // forgetting the partially-substituted parameter pack.
3781 if (RetainExpansion) {
3782 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
Richard Smithd784e682015-09-23 21:41:42 +00003784 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003785 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003787 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3788 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003789 if (Out.getArgument().isNull())
3790 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregor48d24112011-01-10 20:53:55 +00003792 Outputs.addArgument(Out);
3793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003795 continue;
3796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
3798 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003799 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003800 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregor42cafa82010-12-20 17:42:22 +00003802 Outputs.addArgument(Out);
3803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003804
Douglas Gregor42cafa82010-12-20 17:42:22 +00003805 return false;
3806
3807}
3808
Douglas Gregord6ff3322009-08-04 16:50:30 +00003809//===----------------------------------------------------------------------===//
3810// Type transformation
3811//===----------------------------------------------------------------------===//
3812
3813template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003814QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003815 if (getDerived().AlreadyTransformed(T))
3816 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003817
John McCall550e0c22009-10-21 00:40:46 +00003818 // Temporary workaround. All of these transformations should
3819 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003820 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3821 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003822
John McCall31f82722010-11-12 08:19:04 +00003823 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003824
John McCall550e0c22009-10-21 00:40:46 +00003825 if (!NewDI)
3826 return QualType();
3827
3828 return NewDI->getType();
3829}
3830
3831template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003832TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003833 // Refine the base location to the type's location.
3834 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3835 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003836 if (getDerived().AlreadyTransformed(DI->getType()))
3837 return DI;
3838
3839 TypeLocBuilder TLB;
3840
3841 TypeLoc TL = DI->getTypeLoc();
3842 TLB.reserve(TL.getFullDataSize());
3843
John McCall31f82722010-11-12 08:19:04 +00003844 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003845 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003846 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003847
John McCallbcd03502009-12-07 02:54:59 +00003848 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003849}
3850
3851template<typename Derived>
3852QualType
John McCall31f82722010-11-12 08:19:04 +00003853TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003854 switch (T.getTypeLocClass()) {
3855#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003856#define TYPELOC(CLASS, PARENT) \
3857 case TypeLoc::CLASS: \
3858 return getDerived().Transform##CLASS##Type(TLB, \
3859 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003860#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861 }
Mike Stump11289f42009-09-09 15:08:12 +00003862
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003863 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003864}
3865
3866/// FIXME: By default, this routine adds type qualifiers only to types
3867/// that can have qualifiers, and silently suppresses those qualifiers
3868/// that are not permitted (e.g., qualifiers on reference or function
3869/// types). This is the right thing for template instantiation, but
3870/// probably not for other clients.
3871template<typename Derived>
3872QualType
3873TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003874 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003875 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003876
John McCall31f82722010-11-12 08:19:04 +00003877 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003878 if (Result.isNull())
3879 return QualType();
3880
3881 // Silently suppress qualifiers if the result type can't be qualified.
3882 // FIXME: this is the right thing for template instantiation, but
3883 // probably not for other clients.
3884 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003885 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003886
John McCall31168b02011-06-15 23:02:42 +00003887 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003888 // resulting type.
3889 if (Quals.hasObjCLifetime()) {
3890 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3891 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003892 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003893 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003894 // A lifetime qualifier applied to a substituted template parameter
3895 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003896 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003897 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003898 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3899 QualType Replacement = SubstTypeParam->getReplacementType();
3900 Qualifiers Qs = Replacement.getQualifiers();
3901 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003902 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003903 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3904 Qs);
3905 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003906 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003907 Replacement);
3908 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003909 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3910 // 'auto' types behave the same way as template parameters.
3911 QualType Deduced = AutoTy->getDeducedType();
3912 Qualifiers Qs = Deduced.getQualifiers();
3913 Qs.removeObjCLifetime();
3914 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3915 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003916 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003917 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003918 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003919 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003920 // Otherwise, complain about the addition of a qualifier to an
3921 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003922 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003923 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003924 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003925
Douglas Gregore46db902011-06-17 22:11:49 +00003926 Quals.removeObjCLifetime();
3927 }
3928 }
3929 }
John McCallcb0f89a2010-06-05 06:41:15 +00003930 if (!Quals.empty()) {
3931 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003932 // BuildQualifiedType might not add qualifiers if they are invalid.
3933 if (Result.hasLocalQualifiers())
3934 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003935 // No location information to preserve.
3936 }
John McCall550e0c22009-10-21 00:40:46 +00003937
3938 return Result;
3939}
3940
Douglas Gregor14454802011-02-25 02:25:35 +00003941template<typename Derived>
3942TypeLoc
3943TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3944 QualType ObjectType,
3945 NamedDecl *UnqualLookup,
3946 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003947 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003948 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003949
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003950 TypeSourceInfo *TSI =
3951 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3952 if (TSI)
3953 return TSI->getTypeLoc();
3954 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003955}
3956
Douglas Gregor579c15f2011-03-02 18:32:08 +00003957template<typename Derived>
3958TypeSourceInfo *
3959TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3960 QualType ObjectType,
3961 NamedDecl *UnqualLookup,
3962 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003963 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003964 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003965
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003966 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3967 UnqualLookup, SS);
3968}
3969
3970template <typename Derived>
3971TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3972 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3973 CXXScopeSpec &SS) {
3974 QualType T = TL.getType();
3975 assert(!getDerived().AlreadyTransformed(T));
3976
Douglas Gregor579c15f2011-03-02 18:32:08 +00003977 TypeLocBuilder TLB;
3978 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003979
Douglas Gregor579c15f2011-03-02 18:32:08 +00003980 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003981 TemplateSpecializationTypeLoc SpecTL =
3982 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003983
Douglas Gregor579c15f2011-03-02 18:32:08 +00003984 TemplateName Template
3985 = getDerived().TransformTemplateName(SS,
3986 SpecTL.getTypePtr()->getTemplateName(),
3987 SpecTL.getTemplateNameLoc(),
3988 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003989 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003990 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003991
3992 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003993 Template);
3994 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003995 DependentTemplateSpecializationTypeLoc SpecTL =
3996 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003997
Douglas Gregor579c15f2011-03-02 18:32:08 +00003998 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003999 = getDerived().RebuildTemplateName(SS,
4000 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004001 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004002 ObjectType, UnqualLookup);
4003 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004004 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004005
4006 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004007 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004008 Template,
4009 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004010 } else {
4011 // Nothing special needs to be done for these.
4012 Result = getDerived().TransformType(TLB, TL);
4013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004014
4015 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004016 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004017
Douglas Gregor579c15f2011-03-02 18:32:08 +00004018 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4019}
4020
John McCall550e0c22009-10-21 00:40:46 +00004021template <class TyLoc> static inline
4022QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4023 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4024 NewT.setNameLoc(T.getNameLoc());
4025 return T.getType();
4026}
4027
John McCall550e0c22009-10-21 00:40:46 +00004028template<typename Derived>
4029QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004030 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004031 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4032 NewT.setBuiltinLoc(T.getBuiltinLoc());
4033 if (T.needsExtraLocalData())
4034 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4035 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036}
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004039QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004040 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004041 // FIXME: recurse?
4042 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
Reid Kleckner0503a872013-12-05 01:23:43 +00004045template <typename Derived>
4046QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4047 AdjustedTypeLoc TL) {
4048 // Adjustments applied during transformation are handled elsewhere.
4049 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4050}
4051
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004053QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4054 DecayedTypeLoc TL) {
4055 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4056 if (OriginalType.isNull())
4057 return QualType();
4058
4059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 OriginalType != TL.getOriginalLoc().getType())
4062 Result = SemaRef.Context.getDecayedType(OriginalType);
4063 TLB.push<DecayedTypeLoc>(Result);
4064 // Nothing to set for DecayedTypeLoc.
4065 return Result;
4066}
4067
4068template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004069QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004070 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004071 QualType PointeeType
4072 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004073 if (PointeeType.isNull())
4074 return QualType();
4075
4076 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004077 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004078 // A dependent pointer type 'T *' has is being transformed such
4079 // that an Objective-C class type is being replaced for 'T'. The
4080 // resulting pointer type is an ObjCObjectPointerType, not a
4081 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004082 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004083
John McCall8b07ec22010-05-15 11:32:37 +00004084 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4085 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004086 return Result;
4087 }
John McCall31f82722010-11-12 08:19:04 +00004088
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004089 if (getDerived().AlwaysRebuild() ||
4090 PointeeType != TL.getPointeeLoc().getType()) {
4091 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4092 if (Result.isNull())
4093 return QualType();
4094 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004095
John McCall31168b02011-06-15 23:02:42 +00004096 // Objective-C ARC can add lifetime qualifiers to the type that we're
4097 // pointing to.
4098 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004100 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4101 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103}
Mike Stump11289f42009-09-09 15:08:12 +00004104
4105template<typename Derived>
4106QualType
John McCall550e0c22009-10-21 00:40:46 +00004107TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004108 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004109 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004110 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4111 if (PointeeType.isNull())
4112 return QualType();
4113
4114 QualType Result = TL.getType();
4115 if (getDerived().AlwaysRebuild() ||
4116 PointeeType != TL.getPointeeLoc().getType()) {
4117 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004118 TL.getSigilLoc());
4119 if (Result.isNull())
4120 return QualType();
4121 }
4122
Douglas Gregor049211a2010-04-22 16:50:51 +00004123 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004124 NewT.setSigilLoc(TL.getSigilLoc());
4125 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126}
4127
John McCall70dd5f62009-10-30 00:06:24 +00004128/// Transforms a reference type. Note that somewhat paradoxically we
4129/// don't care whether the type itself is an l-value type or an r-value
4130/// type; we only care if the type was *written* as an l-value type
4131/// or an r-value type.
4132template<typename Derived>
4133QualType
4134TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004135 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004136 const ReferenceType *T = TL.getTypePtr();
4137
4138 // Note that this works with the pointee-as-written.
4139 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4140 if (PointeeType.isNull())
4141 return QualType();
4142
4143 QualType Result = TL.getType();
4144 if (getDerived().AlwaysRebuild() ||
4145 PointeeType != T->getPointeeTypeAsWritten()) {
4146 Result = getDerived().RebuildReferenceType(PointeeType,
4147 T->isSpelledAsLValue(),
4148 TL.getSigilLoc());
4149 if (Result.isNull())
4150 return QualType();
4151 }
4152
John McCall31168b02011-06-15 23:02:42 +00004153 // Objective-C ARC can add lifetime qualifiers to the type that we're
4154 // referring to.
4155 TLB.TypeWasModifiedSafely(
4156 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4157
John McCall70dd5f62009-10-30 00:06:24 +00004158 // r-value references can be rebuilt as l-value references.
4159 ReferenceTypeLoc NewTL;
4160 if (isa<LValueReferenceType>(Result))
4161 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4162 else
4163 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4164 NewTL.setSigilLoc(TL.getSigilLoc());
4165
4166 return Result;
4167}
4168
Mike Stump11289f42009-09-09 15:08:12 +00004169template<typename Derived>
4170QualType
John McCall550e0c22009-10-21 00:40:46 +00004171TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 LValueReferenceTypeLoc TL) {
4173 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174}
4175
Mike Stump11289f42009-09-09 15:08:12 +00004176template<typename Derived>
4177QualType
John McCall550e0c22009-10-21 00:40:46 +00004178TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 RValueReferenceTypeLoc TL) {
4180 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004184QualType
John McCall550e0c22009-10-21 00:40:46 +00004185TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004186 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004187 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004188 if (PointeeType.isNull())
4189 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004190
Abramo Bagnara509357842011-03-05 14:42:21 +00004191 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004192 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004193 if (OldClsTInfo) {
4194 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4195 if (!NewClsTInfo)
4196 return QualType();
4197 }
4198
4199 const MemberPointerType *T = TL.getTypePtr();
4200 QualType OldClsType = QualType(T->getClass(), 0);
4201 QualType NewClsType;
4202 if (NewClsTInfo)
4203 NewClsType = NewClsTInfo->getType();
4204 else {
4205 NewClsType = getDerived().TransformType(OldClsType);
4206 if (NewClsType.isNull())
4207 return QualType();
4208 }
Mike Stump11289f42009-09-09 15:08:12 +00004209
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType Result = TL.getType();
4211 if (getDerived().AlwaysRebuild() ||
4212 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004213 NewClsType != OldClsType) {
4214 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004215 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004216 if (Result.isNull())
4217 return QualType();
4218 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219
Reid Kleckner0503a872013-12-05 01:23:43 +00004220 // If we had to adjust the pointee type when building a member pointer, make
4221 // sure to push TypeLoc info for it.
4222 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4223 if (MPT && PointeeType != MPT->getPointeeType()) {
4224 assert(isa<AdjustedType>(MPT->getPointeeType()));
4225 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4226 }
4227
John McCall550e0c22009-10-21 00:40:46 +00004228 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4229 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004230 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004231
4232 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233}
4234
Mike Stump11289f42009-09-09 15:08:12 +00004235template<typename Derived>
4236QualType
John McCall550e0c22009-10-21 00:40:46 +00004237TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004238 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004239 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004240 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004241 if (ElementType.isNull())
4242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004243
John McCall550e0c22009-10-21 00:40:46 +00004244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ElementType != T->getElementType()) {
4247 Result = getDerived().RebuildConstantArrayType(ElementType,
4248 T->getSizeModifier(),
4249 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004250 T->getIndexTypeCVRQualifiers(),
4251 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004252 if (Result.isNull())
4253 return QualType();
4254 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004255
4256 // We might have either a ConstantArrayType or a VariableArrayType now:
4257 // a ConstantArrayType is allowed to have an element type which is a
4258 // VariableArrayType if the type is dependent. Fortunately, all array
4259 // types have the same location layout.
4260 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004261 NewTL.setLBracketLoc(TL.getLBracketLoc());
4262 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004263
John McCall550e0c22009-10-21 00:40:46 +00004264 Expr *Size = TL.getSizeExpr();
4265 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004266 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4267 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004268 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4269 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004270 }
4271 NewTL.setSizeExpr(Size);
4272
4273 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004274}
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregord6ff3322009-08-04 16:50:30 +00004276template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004277QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004278 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004279 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004280 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004281 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282 if (ElementType.isNull())
4283 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004284
John McCall550e0c22009-10-21 00:40:46 +00004285 QualType Result = TL.getType();
4286 if (getDerived().AlwaysRebuild() ||
4287 ElementType != T->getElementType()) {
4288 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004289 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004290 T->getIndexTypeCVRQualifiers(),
4291 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004292 if (Result.isNull())
4293 return QualType();
4294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
John McCall550e0c22009-10-21 00:40:46 +00004296 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4297 NewTL.setLBracketLoc(TL.getLBracketLoc());
4298 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004299 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004300
4301 return Result;
4302}
4303
4304template<typename Derived>
4305QualType
4306TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004307 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004308 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004309 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4310 if (ElementType.isNull())
4311 return QualType();
4312
John McCalldadc5752010-08-24 06:29:42 +00004313 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004314 = getDerived().TransformExpr(T->getSizeExpr());
4315 if (SizeResult.isInvalid())
4316 return QualType();
4317
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004318 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004319
4320 QualType Result = TL.getType();
4321 if (getDerived().AlwaysRebuild() ||
4322 ElementType != T->getElementType() ||
4323 Size != T->getSizeExpr()) {
4324 Result = getDerived().RebuildVariableArrayType(ElementType,
4325 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004326 Size,
John McCall550e0c22009-10-21 00:40:46 +00004327 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004328 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004329 if (Result.isNull())
4330 return QualType();
4331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004332
Serge Pavlov774c6d02014-02-06 03:49:11 +00004333 // We might have constant size array now, but fortunately it has the same
4334 // location layout.
4335 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004336 NewTL.setLBracketLoc(TL.getLBracketLoc());
4337 NewTL.setRBracketLoc(TL.getRBracketLoc());
4338 NewTL.setSizeExpr(Size);
4339
4340 return Result;
4341}
4342
4343template<typename Derived>
4344QualType
4345TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004346 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004347 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004348 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4349 if (ElementType.isNull())
4350 return QualType();
4351
Richard Smith764d2fe2011-12-20 02:08:33 +00004352 // Array bounds are constant expressions.
4353 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4354 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004355
John McCall33ddac02011-01-19 10:06:00 +00004356 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4357 Expr *origSize = TL.getSizeExpr();
4358 if (!origSize) origSize = T->getSizeExpr();
4359
4360 ExprResult sizeResult
4361 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004362 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004363 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004364 return QualType();
4365
John McCall33ddac02011-01-19 10:06:00 +00004366 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004367
4368 QualType Result = TL.getType();
4369 if (getDerived().AlwaysRebuild() ||
4370 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004371 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004372 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4373 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004374 size,
John McCall550e0c22009-10-21 00:40:46 +00004375 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004376 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004377 if (Result.isNull())
4378 return QualType();
4379 }
John McCall550e0c22009-10-21 00:40:46 +00004380
4381 // We might have any sort of array type now, but fortunately they
4382 // all have the same location layout.
4383 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4384 NewTL.setLBracketLoc(TL.getLBracketLoc());
4385 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004386 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004387
4388 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004389}
Mike Stump11289f42009-09-09 15:08:12 +00004390
4391template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004392QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004393 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004394 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004395 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004396
4397 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004398 QualType ElementType = getDerived().TransformType(T->getElementType());
4399 if (ElementType.isNull())
4400 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004401
Richard Smith764d2fe2011-12-20 02:08:33 +00004402 // Vector sizes are constant expressions.
4403 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4404 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004405
John McCalldadc5752010-08-24 06:29:42 +00004406 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004407 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004408 if (Size.isInvalid())
4409 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004410
John McCall550e0c22009-10-21 00:40:46 +00004411 QualType Result = TL.getType();
4412 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004413 ElementType != T->getElementType() ||
4414 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004415 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004416 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004418 if (Result.isNull())
4419 return QualType();
4420 }
John McCall550e0c22009-10-21 00:40:46 +00004421
4422 // Result might be dependent or not.
4423 if (isa<DependentSizedExtVectorType>(Result)) {
4424 DependentSizedExtVectorTypeLoc NewTL
4425 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4426 NewTL.setNameLoc(TL.getNameLoc());
4427 } else {
4428 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4429 NewTL.setNameLoc(TL.getNameLoc());
4430 }
4431
4432 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004433}
Mike Stump11289f42009-09-09 15:08:12 +00004434
4435template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004436QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004437 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004438 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004439 QualType ElementType = getDerived().TransformType(T->getElementType());
4440 if (ElementType.isNull())
4441 return QualType();
4442
John McCall550e0c22009-10-21 00:40:46 +00004443 QualType Result = TL.getType();
4444 if (getDerived().AlwaysRebuild() ||
4445 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004446 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004447 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004448 if (Result.isNull())
4449 return QualType();
4450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004451
John McCall550e0c22009-10-21 00:40:46 +00004452 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4453 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004454
John McCall550e0c22009-10-21 00:40:46 +00004455 return Result;
4456}
4457
4458template<typename Derived>
4459QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004460 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004461 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004462 QualType ElementType = getDerived().TransformType(T->getElementType());
4463 if (ElementType.isNull())
4464 return QualType();
4465
4466 QualType Result = TL.getType();
4467 if (getDerived().AlwaysRebuild() ||
4468 ElementType != T->getElementType()) {
4469 Result = getDerived().RebuildExtVectorType(ElementType,
4470 T->getNumElements(),
4471 /*FIXME*/ SourceLocation());
4472 if (Result.isNull())
4473 return QualType();
4474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004475
John McCall550e0c22009-10-21 00:40:46 +00004476 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4477 NewTL.setNameLoc(TL.getNameLoc());
4478
4479 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004480}
Mike Stump11289f42009-09-09 15:08:12 +00004481
David Blaikie05785d12013-02-20 22:23:23 +00004482template <typename Derived>
4483ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4484 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4485 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004486 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004487 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
Douglas Gregor715e4612011-01-14 22:40:04 +00004489 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004490 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004491 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004492 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004493 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004494
Douglas Gregor715e4612011-01-14 22:40:04 +00004495 TypeLocBuilder TLB;
4496 TypeLoc NewTL = OldDI->getTypeLoc();
4497 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004498
4499 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004500 OldExpansionTL.getPatternLoc());
4501 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004502 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004503
4504 Result = RebuildPackExpansionType(Result,
4505 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004506 OldExpansionTL.getEllipsisLoc(),
4507 NumExpansions);
4508 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004509 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004510
Douglas Gregor715e4612011-01-14 22:40:04 +00004511 PackExpansionTypeLoc NewExpansionTL
4512 = TLB.push<PackExpansionTypeLoc>(Result);
4513 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4514 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4515 } else
4516 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004517 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004518 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004519
John McCall8fb0d9d2011-05-01 22:35:37 +00004520 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004521 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004522
4523 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4524 OldParm->getDeclContext(),
4525 OldParm->getInnerLocStart(),
4526 OldParm->getLocation(),
4527 OldParm->getIdentifier(),
4528 NewDI->getType(),
4529 NewDI,
4530 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004531 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004532 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4533 OldParm->getFunctionScopeIndex() + indexAdjustment);
4534 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004535}
4536
4537template<typename Derived>
4538bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004539 TransformFunctionTypeParams(SourceLocation Loc,
4540 ParmVarDecl **Params, unsigned NumParams,
4541 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004542 SmallVectorImpl<QualType> &OutParamTypes,
4543 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004544 int indexAdjustment = 0;
4545
Douglas Gregordd472162011-01-07 00:20:55 +00004546 for (unsigned i = 0; i != NumParams; ++i) {
4547 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004548 assert(OldParm->getFunctionScopeIndex() == i);
4549
David Blaikie05785d12013-02-20 22:23:23 +00004550 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004551 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004552 if (OldParm->isParameterPack()) {
4553 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004554 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004555
Douglas Gregor5499af42011-01-05 23:12:31 +00004556 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004557 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004558 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004559 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4560 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004561 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4562
Douglas Gregor5499af42011-01-05 23:12:31 +00004563 // Determine whether we should expand the parameter packs.
4564 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004565 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004566 Optional<unsigned> OrigNumExpansions =
4567 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004568 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004569 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4570 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004571 Unexpanded,
4572 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004573 RetainExpansion,
4574 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004575 return true;
4576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004577
Douglas Gregor5499af42011-01-05 23:12:31 +00004578 if (ShouldExpand) {
4579 // Expand the function parameter pack into multiple, separate
4580 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004581 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004582 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004583 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004584 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004585 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004586 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004587 OrigNumExpansions,
4588 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004589 if (!NewParm)
4590 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004591
Douglas Gregordd472162011-01-07 00:20:55 +00004592 OutParamTypes.push_back(NewParm->getType());
4593 if (PVars)
4594 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004595 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004596
4597 // If we're supposed to retain a pack expansion, do so by temporarily
4598 // forgetting the partially-substituted parameter pack.
4599 if (RetainExpansion) {
4600 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004601 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004602 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004603 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004604 OrigNumExpansions,
4605 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004606 if (!NewParm)
4607 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004608
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004609 OutParamTypes.push_back(NewParm->getType());
4610 if (PVars)
4611 PVars->push_back(NewParm);
4612 }
4613
John McCall8fb0d9d2011-05-01 22:35:37 +00004614 // The next parameter should have the same adjustment as the
4615 // last thing we pushed, but we post-incremented indexAdjustment
4616 // on every push. Also, if we push nothing, the adjustment should
4617 // go down by one.
4618 indexAdjustment--;
4619
Douglas Gregor5499af42011-01-05 23:12:31 +00004620 // We're done with the pack expansion.
4621 continue;
4622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004623
4624 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004625 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004626 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4627 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004628 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004629 NumExpansions,
4630 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004631 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004632 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004633 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004634 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004635
John McCall58f10c32010-03-11 09:03:00 +00004636 if (!NewParm)
4637 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004638
Douglas Gregordd472162011-01-07 00:20:55 +00004639 OutParamTypes.push_back(NewParm->getType());
4640 if (PVars)
4641 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004642 continue;
4643 }
John McCall58f10c32010-03-11 09:03:00 +00004644
4645 // Deal with the possibility that we don't have a parameter
4646 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004647 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004648 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004649 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004650 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004651 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004652 = dyn_cast<PackExpansionType>(OldType)) {
4653 // We have a function parameter pack that may need to be expanded.
4654 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004655 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004656 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004657
Douglas Gregor5499af42011-01-05 23:12:31 +00004658 // Determine whether we should expand the parameter packs.
4659 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004660 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004661 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004662 Unexpanded,
4663 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004664 RetainExpansion,
4665 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004666 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004668
Douglas Gregor5499af42011-01-05 23:12:31 +00004669 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004670 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004671 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004672 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004673 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4674 QualType NewType = getDerived().TransformType(Pattern);
4675 if (NewType.isNull())
4676 return true;
John McCall58f10c32010-03-11 09:03:00 +00004677
Douglas Gregordd472162011-01-07 00:20:55 +00004678 OutParamTypes.push_back(NewType);
4679 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004680 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004682
Douglas Gregor5499af42011-01-05 23:12:31 +00004683 // We're done with the pack expansion.
4684 continue;
4685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004686
Douglas Gregor48d24112011-01-10 20:53:55 +00004687 // If we're supposed to retain a pack expansion, do so by temporarily
4688 // forgetting the partially-substituted parameter pack.
4689 if (RetainExpansion) {
4690 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4691 QualType NewType = getDerived().TransformType(Pattern);
4692 if (NewType.isNull())
4693 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004694
Douglas Gregor48d24112011-01-10 20:53:55 +00004695 OutParamTypes.push_back(NewType);
4696 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004697 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004698 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004699
Chad Rosier1dcde962012-08-08 18:46:20 +00004700 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004701 // expansion.
4702 OldType = Expansion->getPattern();
4703 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004704 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4705 NewType = getDerived().TransformType(OldType);
4706 } else {
4707 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004708 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004709
Douglas Gregor5499af42011-01-05 23:12:31 +00004710 if (NewType.isNull())
4711 return true;
4712
4713 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004714 NewType = getSema().Context.getPackExpansionType(NewType,
4715 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004716
Douglas Gregordd472162011-01-07 00:20:55 +00004717 OutParamTypes.push_back(NewType);
4718 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004719 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004720 }
4721
John McCall8fb0d9d2011-05-01 22:35:37 +00004722#ifndef NDEBUG
4723 if (PVars) {
4724 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4725 if (ParmVarDecl *parm = (*PVars)[i])
4726 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004727 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004728#endif
4729
4730 return false;
4731}
John McCall58f10c32010-03-11 09:03:00 +00004732
4733template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004734QualType
John McCall550e0c22009-10-21 00:40:46 +00004735TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004736 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004737 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004738 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004739 return getDerived().TransformFunctionProtoType(
4740 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004741 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4742 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4743 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004744 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004745}
4746
Richard Smith2e321552014-11-12 02:00:47 +00004747template<typename Derived> template<typename Fn>
4748QualType TreeTransform<Derived>::TransformFunctionProtoType(
4749 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4750 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004751 // Transform the parameters and return type.
4752 //
Richard Smithf623c962012-04-17 00:58:00 +00004753 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004754 // When the function has a trailing return type, we instantiate the
4755 // parameters before the return type, since the return type can then refer
4756 // to the parameters themselves (via decltype, sizeof, etc.).
4757 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004758 SmallVector<QualType, 4> ParamTypes;
4759 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004760 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004761
Douglas Gregor7fb25412010-10-01 18:44:50 +00004762 QualType ResultType;
4763
Richard Smith1226c602012-08-14 22:51:13 +00004764 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004765 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004766 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004767 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004768 return QualType();
4769
Douglas Gregor3024f072012-04-16 07:05:22 +00004770 {
4771 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004772 // If a declaration declares a member function or member function
4773 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004774 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004775 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004776 // declarator.
4777 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004778
Alp Toker42a16a62014-01-25 23:51:36 +00004779 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004780 if (ResultType.isNull())
4781 return QualType();
4782 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004783 }
4784 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004785 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004786 if (ResultType.isNull())
4787 return QualType();
4788
Alp Toker9cacbab2014-01-20 20:26:09 +00004789 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004790 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004791 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004792 return QualType();
4793 }
4794
Richard Smith2e321552014-11-12 02:00:47 +00004795 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4796
4797 bool EPIChanged = false;
4798 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4799 return QualType();
4800
4801 // FIXME: Need to transform ConsumedParameters for variadic template
4802 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004803
John McCall550e0c22009-10-21 00:40:46 +00004804 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004805 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004806 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004807 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004808 if (Result.isNull())
4809 return QualType();
4810 }
Mike Stump11289f42009-09-09 15:08:12 +00004811
John McCall550e0c22009-10-21 00:40:46 +00004812 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004813 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004814 NewTL.setLParenLoc(TL.getLParenLoc());
4815 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004816 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004817 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4818 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004819
4820 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004821}
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregord6ff3322009-08-04 16:50:30 +00004823template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004824bool TreeTransform<Derived>::TransformExceptionSpec(
4825 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4826 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4827 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4828
4829 // Instantiate a dynamic noexcept expression, if any.
4830 if (ESI.Type == EST_ComputedNoexcept) {
4831 EnterExpressionEvaluationContext Unevaluated(getSema(),
4832 Sema::ConstantEvaluated);
4833 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4834 if (NoexceptExpr.isInvalid())
4835 return true;
4836
4837 NoexceptExpr = getSema().CheckBooleanCondition(
4838 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4839 if (NoexceptExpr.isInvalid())
4840 return true;
4841
4842 if (!NoexceptExpr.get()->isValueDependent()) {
4843 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4844 NoexceptExpr.get(), nullptr,
4845 diag::err_noexcept_needs_constant_expression,
4846 /*AllowFold*/false);
4847 if (NoexceptExpr.isInvalid())
4848 return true;
4849 }
4850
4851 if (ESI.NoexceptExpr != NoexceptExpr.get())
4852 Changed = true;
4853 ESI.NoexceptExpr = NoexceptExpr.get();
4854 }
4855
4856 if (ESI.Type != EST_Dynamic)
4857 return false;
4858
4859 // Instantiate a dynamic exception specification's type.
4860 for (QualType T : ESI.Exceptions) {
4861 if (const PackExpansionType *PackExpansion =
4862 T->getAs<PackExpansionType>()) {
4863 Changed = true;
4864
4865 // We have a pack expansion. Instantiate it.
4866 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4867 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4868 Unexpanded);
4869 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4870
4871 // Determine whether the set of unexpanded parameter packs can and
4872 // should
4873 // be expanded.
4874 bool Expand = false;
4875 bool RetainExpansion = false;
4876 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4877 // FIXME: Track the location of the ellipsis (and track source location
4878 // information for the types in the exception specification in general).
4879 if (getDerived().TryExpandParameterPacks(
4880 Loc, SourceRange(), Unexpanded, Expand,
4881 RetainExpansion, NumExpansions))
4882 return true;
4883
4884 if (!Expand) {
4885 // We can't expand this pack expansion into separate arguments yet;
4886 // just substitute into the pattern and create a new pack expansion
4887 // type.
4888 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4889 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4890 if (U.isNull())
4891 return true;
4892
4893 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4894 Exceptions.push_back(U);
4895 continue;
4896 }
4897
4898 // Substitute into the pack expansion pattern for each slice of the
4899 // pack.
4900 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4902
4903 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4904 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4905 return true;
4906
4907 Exceptions.push_back(U);
4908 }
4909 } else {
4910 QualType U = getDerived().TransformType(T);
4911 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4912 return true;
4913 if (T != U)
4914 Changed = true;
4915
4916 Exceptions.push_back(U);
4917 }
4918 }
4919
4920 ESI.Exceptions = Exceptions;
4921 return false;
4922}
4923
4924template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004926 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004927 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004928 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004929 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004930 if (ResultType.isNull())
4931 return QualType();
4932
4933 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004934 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004935 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4936
4937 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004938 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004939 NewTL.setLParenLoc(TL.getLParenLoc());
4940 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004941 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004942
4943 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004944}
Mike Stump11289f42009-09-09 15:08:12 +00004945
John McCallb96ec562009-12-04 22:46:56 +00004946template<typename Derived> QualType
4947TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004948 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004949 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004950 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004951 if (!D)
4952 return QualType();
4953
4954 QualType Result = TL.getType();
4955 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4956 Result = getDerived().RebuildUnresolvedUsingType(D);
4957 if (Result.isNull())
4958 return QualType();
4959 }
4960
4961 // We might get an arbitrary type spec type back. We should at
4962 // least always get a type spec type, though.
4963 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4964 NewTL.setNameLoc(TL.getNameLoc());
4965
4966 return Result;
4967}
4968
Douglas Gregord6ff3322009-08-04 16:50:30 +00004969template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004970QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004971 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004972 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004973 TypedefNameDecl *Typedef
4974 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4975 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004976 if (!Typedef)
4977 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004978
John McCall550e0c22009-10-21 00:40:46 +00004979 QualType Result = TL.getType();
4980 if (getDerived().AlwaysRebuild() ||
4981 Typedef != T->getDecl()) {
4982 Result = getDerived().RebuildTypedefType(Typedef);
4983 if (Result.isNull())
4984 return QualType();
4985 }
Mike Stump11289f42009-09-09 15:08:12 +00004986
John McCall550e0c22009-10-21 00:40:46 +00004987 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4988 NewTL.setNameLoc(TL.getNameLoc());
4989
4990 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004991}
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregord6ff3322009-08-04 16:50:30 +00004993template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004994QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004995 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004996 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004997 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4998 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCalldadc5752010-08-24 06:29:42 +00005000 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005001 if (E.isInvalid())
5002 return QualType();
5003
Eli Friedmane4f22df2012-02-29 04:03:55 +00005004 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5005 if (E.isInvalid())
5006 return QualType();
5007
John McCall550e0c22009-10-21 00:40:46 +00005008 QualType Result = TL.getType();
5009 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005010 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005011 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005012 if (Result.isNull())
5013 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005014 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005015 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall550e0c22009-10-21 00:40:46 +00005017 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005018 NewTL.setTypeofLoc(TL.getTypeofLoc());
5019 NewTL.setLParenLoc(TL.getLParenLoc());
5020 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005021
5022 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
5025template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005026QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005027 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005028 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5029 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5030 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005031 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005032
John McCall550e0c22009-10-21 00:40:46 +00005033 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005034 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5035 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005036 if (Result.isNull())
5037 return QualType();
5038 }
Mike Stump11289f42009-09-09 15:08:12 +00005039
John McCall550e0c22009-10-21 00:40:46 +00005040 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005041 NewTL.setTypeofLoc(TL.getTypeofLoc());
5042 NewTL.setLParenLoc(TL.getLParenLoc());
5043 NewTL.setRParenLoc(TL.getRParenLoc());
5044 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005045
5046 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005047}
Mike Stump11289f42009-09-09 15:08:12 +00005048
5049template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005050QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005051 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005052 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005053
Douglas Gregore922c772009-08-04 22:27:00 +00005054 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005055 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5056 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005057
John McCalldadc5752010-08-24 06:29:42 +00005058 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005059 if (E.isInvalid())
5060 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005062 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005063 if (E.isInvalid())
5064 return QualType();
5065
John McCall550e0c22009-10-21 00:40:46 +00005066 QualType Result = TL.getType();
5067 if (getDerived().AlwaysRebuild() ||
5068 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005069 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005070 if (Result.isNull())
5071 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005072 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005073 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005074
John McCall550e0c22009-10-21 00:40:46 +00005075 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5076 NewTL.setNameLoc(TL.getNameLoc());
5077
5078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005079}
5080
5081template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005082QualType TreeTransform<Derived>::TransformUnaryTransformType(
5083 TypeLocBuilder &TLB,
5084 UnaryTransformTypeLoc TL) {
5085 QualType Result = TL.getType();
5086 if (Result->isDependentType()) {
5087 const UnaryTransformType *T = TL.getTypePtr();
5088 QualType NewBase =
5089 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5090 Result = getDerived().RebuildUnaryTransformType(NewBase,
5091 T->getUTTKind(),
5092 TL.getKWLoc());
5093 if (Result.isNull())
5094 return QualType();
5095 }
5096
5097 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5098 NewTL.setKWLoc(TL.getKWLoc());
5099 NewTL.setParensRange(TL.getParensRange());
5100 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5101 return Result;
5102}
5103
5104template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005105QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5106 AutoTypeLoc TL) {
5107 const AutoType *T = TL.getTypePtr();
5108 QualType OldDeduced = T->getDeducedType();
5109 QualType NewDeduced;
5110 if (!OldDeduced.isNull()) {
5111 NewDeduced = getDerived().TransformType(OldDeduced);
5112 if (NewDeduced.isNull())
5113 return QualType();
5114 }
5115
5116 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005117 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5118 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005119 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005120 if (Result.isNull())
5121 return QualType();
5122 }
5123
5124 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5125 NewTL.setNameLoc(TL.getNameLoc());
5126
5127 return Result;
5128}
5129
5130template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005131QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005132 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005133 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005134 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005135 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5136 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005137 if (!Record)
5138 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005139
John McCall550e0c22009-10-21 00:40:46 +00005140 QualType Result = TL.getType();
5141 if (getDerived().AlwaysRebuild() ||
5142 Record != T->getDecl()) {
5143 Result = getDerived().RebuildRecordType(Record);
5144 if (Result.isNull())
5145 return QualType();
5146 }
Mike Stump11289f42009-09-09 15:08:12 +00005147
John McCall550e0c22009-10-21 00:40:46 +00005148 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5149 NewTL.setNameLoc(TL.getNameLoc());
5150
5151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
5154template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005155QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005156 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005157 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005158 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005159 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5160 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161 if (!Enum)
5162 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005163
John McCall550e0c22009-10-21 00:40:46 +00005164 QualType Result = TL.getType();
5165 if (getDerived().AlwaysRebuild() ||
5166 Enum != T->getDecl()) {
5167 Result = getDerived().RebuildEnumType(Enum);
5168 if (Result.isNull())
5169 return QualType();
5170 }
Mike Stump11289f42009-09-09 15:08:12 +00005171
John McCall550e0c22009-10-21 00:40:46 +00005172 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5173 NewTL.setNameLoc(TL.getNameLoc());
5174
5175 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005176}
John McCallfcc33b02009-09-05 00:15:47 +00005177
John McCalle78aac42010-03-10 03:28:59 +00005178template<typename Derived>
5179QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5180 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005181 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005182 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5183 TL.getTypePtr()->getDecl());
5184 if (!D) return QualType();
5185
5186 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5187 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5188 return T;
5189}
5190
Douglas Gregord6ff3322009-08-04 16:50:30 +00005191template<typename Derived>
5192QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005193 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005194 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005195 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005196}
5197
Mike Stump11289f42009-09-09 15:08:12 +00005198template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005199QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005200 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005201 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005202 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005203
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005204 // Substitute into the replacement type, which itself might involve something
5205 // that needs to be transformed. This only tends to occur with default
5206 // template arguments of template template parameters.
5207 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5208 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5209 if (Replacement.isNull())
5210 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005211
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005212 // Always canonicalize the replacement type.
5213 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5214 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005215 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005216 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005217
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005218 // Propagate type-source information.
5219 SubstTemplateTypeParmTypeLoc NewTL
5220 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5221 NewTL.setNameLoc(TL.getNameLoc());
5222 return Result;
5223
John McCallcebee162009-10-18 09:09:24 +00005224}
5225
5226template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005227QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5228 TypeLocBuilder &TLB,
5229 SubstTemplateTypeParmPackTypeLoc TL) {
5230 return TransformTypeSpecType(TLB, TL);
5231}
5232
5233template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005234QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005235 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005236 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005237 const TemplateSpecializationType *T = TL.getTypePtr();
5238
Douglas Gregordf846d12011-03-02 18:46:51 +00005239 // The nested-name-specifier never matters in a TemplateSpecializationType,
5240 // because we can't have a dependent nested-name-specifier anyway.
5241 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005242 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005243 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5244 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245 if (Template.isNull())
5246 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005247
John McCall31f82722010-11-12 08:19:04 +00005248 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5249}
5250
Eli Friedman0dfb8892011-10-06 23:00:33 +00005251template<typename Derived>
5252QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5253 AtomicTypeLoc TL) {
5254 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5255 if (ValueType.isNull())
5256 return QualType();
5257
5258 QualType Result = TL.getType();
5259 if (getDerived().AlwaysRebuild() ||
5260 ValueType != TL.getValueLoc().getType()) {
5261 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5262 if (Result.isNull())
5263 return QualType();
5264 }
5265
5266 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5267 NewTL.setKWLoc(TL.getKWLoc());
5268 NewTL.setLParenLoc(TL.getLParenLoc());
5269 NewTL.setRParenLoc(TL.getRParenLoc());
5270
5271 return Result;
5272}
5273
Chad Rosier1dcde962012-08-08 18:46:20 +00005274 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005275 /// container that provides a \c getArgLoc() member function.
5276 ///
5277 /// This iterator is intended to be used with the iterator form of
5278 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5279 template<typename ArgLocContainer>
5280 class TemplateArgumentLocContainerIterator {
5281 ArgLocContainer *Container;
5282 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005283
Douglas Gregorfe921a72010-12-20 23:36:19 +00005284 public:
5285 typedef TemplateArgumentLoc value_type;
5286 typedef TemplateArgumentLoc reference;
5287 typedef int difference_type;
5288 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005289
Douglas Gregorfe921a72010-12-20 23:36:19 +00005290 class pointer {
5291 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005292
Douglas Gregorfe921a72010-12-20 23:36:19 +00005293 public:
5294 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
Douglas Gregorfe921a72010-12-20 23:36:19 +00005296 const TemplateArgumentLoc *operator->() const {
5297 return &Arg;
5298 }
5299 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
5301
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005302 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005303
Douglas Gregorfe921a72010-12-20 23:36:19 +00005304 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5305 unsigned Index)
5306 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005307
Douglas Gregorfe921a72010-12-20 23:36:19 +00005308 TemplateArgumentLocContainerIterator &operator++() {
5309 ++Index;
5310 return *this;
5311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregorfe921a72010-12-20 23:36:19 +00005313 TemplateArgumentLocContainerIterator operator++(int) {
5314 TemplateArgumentLocContainerIterator Old(*this);
5315 ++(*this);
5316 return Old;
5317 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005318
Douglas Gregorfe921a72010-12-20 23:36:19 +00005319 TemplateArgumentLoc operator*() const {
5320 return Container->getArgLoc(Index);
5321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005322
Douglas Gregorfe921a72010-12-20 23:36:19 +00005323 pointer operator->() const {
5324 return pointer(Container->getArgLoc(Index));
5325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregorfe921a72010-12-20 23:36:19 +00005327 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005328 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005329 return X.Container == Y.Container && X.Index == Y.Index;
5330 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005331
Douglas Gregorfe921a72010-12-20 23:36:19 +00005332 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005333 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005334 return !(X == Y);
5335 }
5336 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005337
5338
John McCall31f82722010-11-12 08:19:04 +00005339template <typename Derived>
5340QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5341 TypeLocBuilder &TLB,
5342 TemplateSpecializationTypeLoc TL,
5343 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005344 TemplateArgumentListInfo NewTemplateArgs;
5345 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5346 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005347 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5348 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005349 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005350 ArgIterator(TL, TL.getNumArgs()),
5351 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005352 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005353
John McCall0ad16662009-10-29 08:12:44 +00005354 // FIXME: maybe don't rebuild if all the template arguments are the same.
5355
5356 QualType Result =
5357 getDerived().RebuildTemplateSpecializationType(Template,
5358 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005359 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005360
5361 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005362 // Specializations of template template parameters are represented as
5363 // TemplateSpecializationTypes, and substitution of type alias templates
5364 // within a dependent context can transform them into
5365 // DependentTemplateSpecializationTypes.
5366 if (isa<DependentTemplateSpecializationType>(Result)) {
5367 DependentTemplateSpecializationTypeLoc NewTL
5368 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005369 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005370 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005371 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005372 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005373 NewTL.setLAngleLoc(TL.getLAngleLoc());
5374 NewTL.setRAngleLoc(TL.getRAngleLoc());
5375 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5376 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5377 return Result;
5378 }
5379
John McCall0ad16662009-10-29 08:12:44 +00005380 TemplateSpecializationTypeLoc NewTL
5381 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005382 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005383 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5384 NewTL.setLAngleLoc(TL.getLAngleLoc());
5385 NewTL.setRAngleLoc(TL.getRAngleLoc());
5386 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5387 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005388 }
Mike Stump11289f42009-09-09 15:08:12 +00005389
John McCall0ad16662009-10-29 08:12:44 +00005390 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregor5a064722011-02-28 17:23:35 +00005393template <typename Derived>
5394QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5395 TypeLocBuilder &TLB,
5396 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005397 TemplateName Template,
5398 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005399 TemplateArgumentListInfo NewTemplateArgs;
5400 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5401 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5402 typedef TemplateArgumentLocContainerIterator<
5403 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005404 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005405 ArgIterator(TL, TL.getNumArgs()),
5406 NewTemplateArgs))
5407 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005408
Douglas Gregor5a064722011-02-28 17:23:35 +00005409 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005410
Douglas Gregor5a064722011-02-28 17:23:35 +00005411 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5412 QualType Result
5413 = getSema().Context.getDependentTemplateSpecializationType(
5414 TL.getTypePtr()->getKeyword(),
5415 DTN->getQualifier(),
5416 DTN->getIdentifier(),
5417 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005418
Douglas Gregor5a064722011-02-28 17:23:35 +00005419 DependentTemplateSpecializationTypeLoc NewTL
5420 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005421 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005422 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005423 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005424 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005425 NewTL.setLAngleLoc(TL.getLAngleLoc());
5426 NewTL.setRAngleLoc(TL.getRAngleLoc());
5427 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5428 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5429 return Result;
5430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
5432 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005433 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005434 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005435 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005436
Douglas Gregor5a064722011-02-28 17:23:35 +00005437 if (!Result.isNull()) {
5438 /// FIXME: Wrap this in an elaborated-type-specifier?
5439 TemplateSpecializationTypeLoc NewTL
5440 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005441 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005442 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005443 NewTL.setLAngleLoc(TL.getLAngleLoc());
5444 NewTL.setRAngleLoc(TL.getRAngleLoc());
5445 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5446 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5447 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005448
Douglas Gregor5a064722011-02-28 17:23:35 +00005449 return Result;
5450}
5451
Mike Stump11289f42009-09-09 15:08:12 +00005452template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005453QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005454TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005455 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005456 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005457
Douglas Gregor844cb502011-03-01 18:12:44 +00005458 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005459 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005460 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005461 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005462 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5463 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005464 return QualType();
5465 }
Mike Stump11289f42009-09-09 15:08:12 +00005466
John McCall31f82722010-11-12 08:19:04 +00005467 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5468 if (NamedT.isNull())
5469 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005470
Richard Smith3f1b5d02011-05-05 21:57:07 +00005471 // C++0x [dcl.type.elab]p2:
5472 // If the identifier resolves to a typedef-name or the simple-template-id
5473 // resolves to an alias template specialization, the
5474 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005475 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5476 if (const TemplateSpecializationType *TST =
5477 NamedT->getAs<TemplateSpecializationType>()) {
5478 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005479 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5480 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005481 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5482 diag::err_tag_reference_non_tag) << 4;
5483 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5484 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005485 }
5486 }
5487
John McCall550e0c22009-10-21 00:40:46 +00005488 QualType Result = TL.getType();
5489 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005490 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005491 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005492 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005493 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005494 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005495 if (Result.isNull())
5496 return QualType();
5497 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005498
Abramo Bagnara6150c882010-05-11 21:36:43 +00005499 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005500 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005501 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005502 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005503}
Mike Stump11289f42009-09-09 15:08:12 +00005504
5505template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005506QualType TreeTransform<Derived>::TransformAttributedType(
5507 TypeLocBuilder &TLB,
5508 AttributedTypeLoc TL) {
5509 const AttributedType *oldType = TL.getTypePtr();
5510 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5511 if (modifiedType.isNull())
5512 return QualType();
5513
5514 QualType result = TL.getType();
5515
5516 // FIXME: dependent operand expressions?
5517 if (getDerived().AlwaysRebuild() ||
5518 modifiedType != oldType->getModifiedType()) {
5519 // TODO: this is really lame; we should really be rebuilding the
5520 // equivalent type from first principles.
5521 QualType equivalentType
5522 = getDerived().TransformType(oldType->getEquivalentType());
5523 if (equivalentType.isNull())
5524 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005525
5526 // Check whether we can add nullability; it is only represented as
5527 // type sugar, and therefore cannot be diagnosed in any other way.
5528 if (auto nullability = oldType->getImmediateNullability()) {
5529 if (!modifiedType->canHaveNullability()) {
5530 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005531 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005532 return QualType();
5533 }
5534 }
5535
John McCall81904512011-01-06 01:58:22 +00005536 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5537 modifiedType,
5538 equivalentType);
5539 }
5540
5541 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5542 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5543 if (TL.hasAttrOperand())
5544 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5545 if (TL.hasAttrExprOperand())
5546 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5547 else if (TL.hasAttrEnumOperand())
5548 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5549
5550 return result;
5551}
5552
5553template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005554QualType
5555TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5556 ParenTypeLoc TL) {
5557 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5558 if (Inner.isNull())
5559 return QualType();
5560
5561 QualType Result = TL.getType();
5562 if (getDerived().AlwaysRebuild() ||
5563 Inner != TL.getInnerLoc().getType()) {
5564 Result = getDerived().RebuildParenType(Inner);
5565 if (Result.isNull())
5566 return QualType();
5567 }
5568
5569 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5570 NewTL.setLParenLoc(TL.getLParenLoc());
5571 NewTL.setRParenLoc(TL.getRParenLoc());
5572 return Result;
5573}
5574
5575template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005576QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005577 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005578 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005579
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005580 NestedNameSpecifierLoc QualifierLoc
5581 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5582 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005583 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005584
John McCallc392f372010-06-11 00:33:02 +00005585 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005586 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005587 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005588 QualifierLoc,
5589 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005590 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005591 if (Result.isNull())
5592 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005593
Abramo Bagnarad7548482010-05-19 21:37:53 +00005594 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5595 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005596 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5597
Abramo Bagnarad7548482010-05-19 21:37:53 +00005598 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005599 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005600 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005601 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005602 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005603 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005604 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005605 NewTL.setNameLoc(TL.getNameLoc());
5606 }
John McCall550e0c22009-10-21 00:40:46 +00005607 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005608}
Mike Stump11289f42009-09-09 15:08:12 +00005609
Douglas Gregord6ff3322009-08-04 16:50:30 +00005610template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005611QualType TreeTransform<Derived>::
5612 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005613 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005614 NestedNameSpecifierLoc QualifierLoc;
5615 if (TL.getQualifierLoc()) {
5616 QualifierLoc
5617 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5618 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005619 return QualType();
5620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005621
John McCall31f82722010-11-12 08:19:04 +00005622 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005623 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005624}
5625
5626template<typename Derived>
5627QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005628TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5629 DependentTemplateSpecializationTypeLoc TL,
5630 NestedNameSpecifierLoc QualifierLoc) {
5631 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005632
Douglas Gregora7a795b2011-03-01 20:11:18 +00005633 TemplateArgumentListInfo NewTemplateArgs;
5634 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5635 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005636
Douglas Gregora7a795b2011-03-01 20:11:18 +00005637 typedef TemplateArgumentLocContainerIterator<
5638 DependentTemplateSpecializationTypeLoc> ArgIterator;
5639 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5640 ArgIterator(TL, TL.getNumArgs()),
5641 NewTemplateArgs))
5642 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005643
Douglas Gregora7a795b2011-03-01 20:11:18 +00005644 QualType Result
5645 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5646 QualifierLoc,
5647 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005648 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005649 NewTemplateArgs);
5650 if (Result.isNull())
5651 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005652
Douglas Gregora7a795b2011-03-01 20:11:18 +00005653 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5654 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005655
Douglas Gregora7a795b2011-03-01 20:11:18 +00005656 // Copy information relevant to the template specialization.
5657 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005658 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005659 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005660 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005661 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5662 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005663 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005664 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005665
Douglas Gregora7a795b2011-03-01 20:11:18 +00005666 // Copy information relevant to the elaborated type.
5667 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005668 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005669 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005670 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5671 DependentTemplateSpecializationTypeLoc SpecTL
5672 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005673 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005674 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005675 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005676 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005677 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5678 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005679 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005680 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005681 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005682 TemplateSpecializationTypeLoc SpecTL
5683 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005684 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005685 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005686 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5687 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005688 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005689 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005690 }
5691 return Result;
5692}
5693
5694template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005695QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5696 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005697 QualType Pattern
5698 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005699 if (Pattern.isNull())
5700 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005701
5702 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005703 if (getDerived().AlwaysRebuild() ||
5704 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005705 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005706 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005707 TL.getEllipsisLoc(),
5708 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005709 if (Result.isNull())
5710 return QualType();
5711 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005712
Douglas Gregor822d0302011-01-12 17:07:58 +00005713 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5714 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5715 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005716}
5717
5718template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005719QualType
5720TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005721 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005722 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005723 TLB.pushFullCopy(TL);
5724 return TL.getType();
5725}
5726
5727template<typename Derived>
5728QualType
5729TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005730 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005731 // Transform base type.
5732 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5733 if (BaseType.isNull())
5734 return QualType();
5735
5736 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5737
5738 // Transform type arguments.
5739 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5740 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5741 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5742 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5743 QualType TypeArg = TypeArgInfo->getType();
5744 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5745 AnyChanged = true;
5746
5747 // We have a pack expansion. Instantiate it.
5748 const auto *PackExpansion = PackExpansionLoc.getType()
5749 ->castAs<PackExpansionType>();
5750 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5751 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5752 Unexpanded);
5753 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5754
5755 // Determine whether the set of unexpanded parameter packs can
5756 // and should be expanded.
5757 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5758 bool Expand = false;
5759 bool RetainExpansion = false;
5760 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5761 if (getDerived().TryExpandParameterPacks(
5762 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5763 Unexpanded, Expand, RetainExpansion, NumExpansions))
5764 return QualType();
5765
5766 if (!Expand) {
5767 // We can't expand this pack expansion into separate arguments yet;
5768 // just substitute into the pattern and create a new pack expansion
5769 // type.
5770 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5771
5772 TypeLocBuilder TypeArgBuilder;
5773 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5774 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5775 PatternLoc);
5776 if (NewPatternType.isNull())
5777 return QualType();
5778
5779 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5780 NewPatternType, NumExpansions);
5781 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5782 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5783 NewTypeArgInfos.push_back(
5784 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5785 continue;
5786 }
5787
5788 // Substitute into the pack expansion pattern for each slice of the
5789 // pack.
5790 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5791 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5792
5793 TypeLocBuilder TypeArgBuilder;
5794 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5795
5796 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5797 PatternLoc);
5798 if (NewTypeArg.isNull())
5799 return QualType();
5800
5801 NewTypeArgInfos.push_back(
5802 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5803 }
5804
5805 continue;
5806 }
5807
5808 TypeLocBuilder TypeArgBuilder;
5809 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5810 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5811 if (NewTypeArg.isNull())
5812 return QualType();
5813
5814 // If nothing changed, just keep the old TypeSourceInfo.
5815 if (NewTypeArg == TypeArg) {
5816 NewTypeArgInfos.push_back(TypeArgInfo);
5817 continue;
5818 }
5819
5820 NewTypeArgInfos.push_back(
5821 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5822 AnyChanged = true;
5823 }
5824
5825 QualType Result = TL.getType();
5826 if (getDerived().AlwaysRebuild() || AnyChanged) {
5827 // Rebuild the type.
5828 Result = getDerived().RebuildObjCObjectType(
5829 BaseType,
5830 TL.getLocStart(),
5831 TL.getTypeArgsLAngleLoc(),
5832 NewTypeArgInfos,
5833 TL.getTypeArgsRAngleLoc(),
5834 TL.getProtocolLAngleLoc(),
5835 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5836 TL.getNumProtocols()),
5837 TL.getProtocolLocs(),
5838 TL.getProtocolRAngleLoc());
5839
5840 if (Result.isNull())
5841 return QualType();
5842 }
5843
5844 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5845 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5846 NewT.setHasBaseTypeAsWritten(true);
5847 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5848 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5849 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5850 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5851 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5852 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5853 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5854 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5855 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005856}
Mike Stump11289f42009-09-09 15:08:12 +00005857
5858template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005859QualType
5860TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005861 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005862 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5863 if (PointeeType.isNull())
5864 return QualType();
5865
5866 QualType Result = TL.getType();
5867 if (getDerived().AlwaysRebuild() ||
5868 PointeeType != TL.getPointeeLoc().getType()) {
5869 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5870 TL.getStarLoc());
5871 if (Result.isNull())
5872 return QualType();
5873 }
5874
5875 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5876 NewT.setStarLoc(TL.getStarLoc());
5877 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005878}
5879
Douglas Gregord6ff3322009-08-04 16:50:30 +00005880//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005881// Statement transformation
5882//===----------------------------------------------------------------------===//
5883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005884StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005885TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005886 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005887}
5888
5889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005890StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005891TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5892 return getDerived().TransformCompoundStmt(S, false);
5893}
5894
5895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005896StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005897TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005898 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005899 Sema::CompoundScopeRAII CompoundScope(getSema());
5900
John McCall1ababa62010-08-27 19:56:05 +00005901 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005902 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005903 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005904 for (auto *B : S->body()) {
5905 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005906 if (Result.isInvalid()) {
5907 // Immediately fail if this was a DeclStmt, since it's very
5908 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005909 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005910 return StmtError();
5911
5912 // Otherwise, just keep processing substatements and fail later.
5913 SubStmtInvalid = true;
5914 continue;
5915 }
Mike Stump11289f42009-09-09 15:08:12 +00005916
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005917 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005918 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005919 }
Mike Stump11289f42009-09-09 15:08:12 +00005920
John McCall1ababa62010-08-27 19:56:05 +00005921 if (SubStmtInvalid)
5922 return StmtError();
5923
Douglas Gregorebe10102009-08-20 07:17:43 +00005924 if (!getDerived().AlwaysRebuild() &&
5925 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005926 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005927
5928 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005929 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 S->getRBracLoc(),
5931 IsStmtExpr);
5932}
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregorebe10102009-08-20 07:17:43 +00005934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005935StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005936TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005937 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005938 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005939 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5940 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005941
Eli Friedman06577382009-11-19 03:14:00 +00005942 // Transform the left-hand case value.
5943 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005944 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005945 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005947
Eli Friedman06577382009-11-19 03:14:00 +00005948 // Transform the right-hand case value (for the GNU case-range extension).
5949 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005950 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005951 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005953 }
Mike Stump11289f42009-09-09 15:08:12 +00005954
Douglas Gregorebe10102009-08-20 07:17:43 +00005955 // Build the case statement.
5956 // Case statements are always rebuilt so that they will attached to their
5957 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005958 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005959 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005960 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005961 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005962 S->getColonLoc());
5963 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregorebe10102009-08-20 07:17:43 +00005966 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005967 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005968 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005970
Douglas Gregorebe10102009-08-20 07:17:43 +00005971 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005972 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005973}
5974
5975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005976StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005977TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005978 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005979 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005980 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 // Default statements are always rebuilt
5984 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005985 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005986}
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregorebe10102009-08-20 07:17:43 +00005988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005989StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005990TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005991 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005992 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005993 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005994
Chris Lattnercab02a62011-02-17 20:34:02 +00005995 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5996 S->getDecl());
5997 if (!LD)
5998 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005999
6000
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006002 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006003 cast<LabelDecl>(LD), SourceLocation(),
6004 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006005}
Mike Stump11289f42009-09-09 15:08:12 +00006006
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006007template <typename Derived>
6008const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6009 if (!R)
6010 return R;
6011
6012 switch (R->getKind()) {
6013// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6014#define ATTR(X)
6015#define PRAGMA_SPELLING_ATTR(X) \
6016 case attr::X: \
6017 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6018#include "clang/Basic/AttrList.inc"
6019 default:
6020 return R;
6021 }
6022}
6023
6024template <typename Derived>
6025StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6026 bool AttrsChanged = false;
6027 SmallVector<const Attr *, 1> Attrs;
6028
6029 // Visit attributes and keep track if any are transformed.
6030 for (const auto *I : S->getAttrs()) {
6031 const Attr *R = getDerived().TransformAttr(I);
6032 AttrsChanged |= (I != R);
6033 Attrs.push_back(R);
6034 }
6035
Richard Smithc202b282012-04-14 00:33:13 +00006036 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6037 if (SubStmt.isInvalid())
6038 return StmtError();
6039
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006040 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006041 return S;
6042
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006043 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006044 SubStmt.get());
6045}
6046
6047template<typename Derived>
6048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006049TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006050 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006051 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006052 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006053 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006054 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006055 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006056 getDerived().TransformDefinition(
6057 S->getConditionVariable()->getLocation(),
6058 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006059 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006061 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006062 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006063
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006064 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006065 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006066
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006067 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006068 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006069 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006070 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006071 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006073
John McCallb268a282010-08-23 23:25:46 +00006074 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006075 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006078 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006079 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006081
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006083 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006084 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006085 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006086
Douglas Gregorebe10102009-08-20 07:17:43 +00006087 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006088 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006089 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006090 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregorebe10102009-08-20 07:17:43 +00006092 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006093 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006094 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 Then.get() == S->getThen() &&
6096 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006097 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006098
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006099 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006100 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006101 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006102}
6103
6104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006105StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006106TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006107 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006108 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006109 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006110 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006111 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006112 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006113 getDerived().TransformDefinition(
6114 S->getConditionVariable()->getLocation(),
6115 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006116 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006118 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006119 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006121 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006123 }
Mike Stump11289f42009-09-09 15:08:12 +00006124
Douglas Gregorebe10102009-08-20 07:17:43 +00006125 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006126 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006127 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006128 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006129 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregorebe10102009-08-20 07:17:43 +00006132 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006133 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006138 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6139 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006140}
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorebe10102009-08-20 07:17:43 +00006142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006143StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006144TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006145 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006146 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006147 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006148 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006149 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006150 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006151 getDerived().TransformDefinition(
6152 S->getConditionVariable()->getLocation(),
6153 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006154 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006156 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006157 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006158
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006159 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006160 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006161
6162 if (S->getCond()) {
6163 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006164 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6165 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006166 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006167 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006168 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006169 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006170 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006171 }
Mike Stump11289f42009-09-09 15:08:12 +00006172
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006173 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006174 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006176
Douglas Gregorebe10102009-08-20 07:17:43 +00006177 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006178 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregorebe10102009-08-20 07:17:43 +00006182 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006183 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006184 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006186 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006188 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006189 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006190}
Mike Stump11289f42009-09-09 15:08:12 +00006191
Douglas Gregorebe10102009-08-20 07:17:43 +00006192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006193StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006194TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006196 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006197 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006199
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006200 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006201 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006202 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregorebe10102009-08-20 07:17:43 +00006205 if (!getDerived().AlwaysRebuild() &&
6206 Cond.get() == S->getCond() &&
6207 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006208 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006209
John McCallb268a282010-08-23 23:25:46 +00006210 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6211 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006212 S->getRParenLoc());
6213}
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregorebe10102009-08-20 07:17:43 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006217TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006219 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006220 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006221 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregorebe10102009-08-20 07:17:43 +00006223 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006224 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006225 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006226 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006227 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006228 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006229 getDerived().TransformDefinition(
6230 S->getConditionVariable()->getLocation(),
6231 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006232 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006234 } else {
6235 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006236
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006237 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006239
6240 if (S->getCond()) {
6241 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006242 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6243 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006244 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006245 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006246 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006247
John McCallb268a282010-08-23 23:25:46 +00006248 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006249 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006250 }
Mike Stump11289f42009-09-09 15:08:12 +00006251
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006254 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006255
Douglas Gregorebe10102009-08-20 07:17:43 +00006256 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006257 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006259 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006260
Richard Smith945f8d32013-01-14 22:39:08 +00006261 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006262 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006266 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006267 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006268 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 if (!getDerived().AlwaysRebuild() &&
6271 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006272 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006273 Inc.get() == S->getInc() &&
6274 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006275 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006276
Douglas Gregorebe10102009-08-20 07:17:43 +00006277 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006278 Init.get(), FullCond, ConditionVar,
6279 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006280}
6281
6282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006283StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006284TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006285 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6286 S->getLabel());
6287 if (!LD)
6288 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006289
Douglas Gregorebe10102009-08-20 07:17:43 +00006290 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006291 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006292 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006293}
6294
6295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006296StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006297TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006298 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006299 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006301 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregorebe10102009-08-20 07:17:43 +00006303 if (!getDerived().AlwaysRebuild() &&
6304 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006305 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006306
6307 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006308 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006309}
6310
6311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006312StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006313TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006314 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006315}
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregorebe10102009-08-20 07:17:43 +00006317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006318StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006319TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006320 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006321}
Mike Stump11289f42009-09-09 15:08:12 +00006322
Douglas Gregorebe10102009-08-20 07:17:43 +00006323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006324StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006325TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006326 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6327 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006328 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006330
Mike Stump11289f42009-09-09 15:08:12 +00006331 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006333 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006334}
Mike Stump11289f42009-09-09 15:08:12 +00006335
Douglas Gregorebe10102009-08-20 07:17:43 +00006336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006337StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006338TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006339 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006340 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006341 for (auto *D : S->decls()) {
6342 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006343 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006345
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006346 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006347 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregorebe10102009-08-20 07:17:43 +00006349 Decls.push_back(Transformed);
6350 }
Mike Stump11289f42009-09-09 15:08:12 +00006351
Douglas Gregorebe10102009-08-20 07:17:43 +00006352 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006353 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006354
Rafael Espindolaab417692013-07-09 12:05:01 +00006355 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006356}
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregorebe10102009-08-20 07:17:43 +00006358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006359StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006360TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006361
Benjamin Kramerf0623432012-08-23 22:51:59 +00006362 SmallVector<Expr*, 8> Constraints;
6363 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006364 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006365
John McCalldadc5752010-08-24 06:29:42 +00006366 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006367 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006368
6369 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006370
Anders Carlssonaaeef072010-01-24 05:50:09 +00006371 // Go through the outputs.
6372 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006373 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006374
Anders Carlssonaaeef072010-01-24 05:50:09 +00006375 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006376 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006377
Anders Carlssonaaeef072010-01-24 05:50:09 +00006378 // Transform the output expr.
6379 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006380 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006381 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006383
Anders Carlssonaaeef072010-01-24 05:50:09 +00006384 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006385
John McCallb268a282010-08-23 23:25:46 +00006386 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006388
Anders Carlssonaaeef072010-01-24 05:50:09 +00006389 // Go through the inputs.
6390 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006391 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006392
Anders Carlssonaaeef072010-01-24 05:50:09 +00006393 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006394 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006395
Anders Carlssonaaeef072010-01-24 05:50:09 +00006396 // Transform the input expr.
6397 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006398 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006399 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006401
Anders Carlssonaaeef072010-01-24 05:50:09 +00006402 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006403
John McCallb268a282010-08-23 23:25:46 +00006404 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006406
Anders Carlssonaaeef072010-01-24 05:50:09 +00006407 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006408 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006409
6410 // Go through the clobbers.
6411 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006412 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006413
6414 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006415 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006416 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6417 S->isVolatile(), S->getNumOutputs(),
6418 S->getNumInputs(), Names.data(),
6419 Constraints, Exprs, AsmString.get(),
6420 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006421}
6422
Chad Rosier32503022012-06-11 20:47:18 +00006423template<typename Derived>
6424StmtResult
6425TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006426 ArrayRef<Token> AsmToks =
6427 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006428
John McCallf413f5e2013-05-03 00:10:13 +00006429 bool HadError = false, HadChange = false;
6430
6431 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6432 SmallVector<Expr*, 8> TransformedExprs;
6433 TransformedExprs.reserve(SrcExprs.size());
6434 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6435 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6436 if (!Result.isUsable()) {
6437 HadError = true;
6438 } else {
6439 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006440 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006441 }
6442 }
6443
6444 if (HadError) return StmtError();
6445 if (!HadChange && !getDerived().AlwaysRebuild())
6446 return Owned(S);
6447
Chad Rosierb6f46c12012-08-15 16:53:30 +00006448 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006449 AsmToks, S->getAsmString(),
6450 S->getNumOutputs(), S->getNumInputs(),
6451 S->getAllConstraints(), S->getClobbers(),
6452 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006453}
Douglas Gregorebe10102009-08-20 07:17:43 +00006454
Richard Smith9f690bd2015-10-27 06:02:45 +00006455// C++ Coroutines TS
6456
6457template<typename Derived>
6458StmtResult
6459TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6460 // The coroutine body should be re-formed by the caller if necessary.
6461 return getDerived().TransformStmt(S->getBody());
6462}
6463
6464template<typename Derived>
6465StmtResult
6466TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6467 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6468 /*NotCopyInit*/false);
6469 if (Result.isInvalid())
6470 return StmtError();
6471
6472 // Always rebuild; we don't know if this needs to be injected into a new
6473 // context or if the promise type has changed.
6474 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6475}
6476
6477template<typename Derived>
6478ExprResult
6479TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6480 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6481 /*NotCopyInit*/false);
6482 if (Result.isInvalid())
6483 return ExprError();
6484
6485 // Always rebuild; we don't know if this needs to be injected into a new
6486 // context or if the promise type has changed.
6487 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6488}
6489
6490template<typename Derived>
6491ExprResult
6492TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6493 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6494 /*NotCopyInit*/false);
6495 if (Result.isInvalid())
6496 return ExprError();
6497
6498 // Always rebuild; we don't know if this needs to be injected into a new
6499 // context or if the promise type has changed.
6500 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6501}
6502
6503// Objective-C Statements.
6504
Douglas Gregorebe10102009-08-20 07:17:43 +00006505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006507TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006508 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006509 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006510 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006511 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006512
Douglas Gregor96c79492010-04-23 22:50:49 +00006513 // Transform the @catch statements (if present).
6514 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006515 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006516 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006517 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006518 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006519 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006520 if (Catch.get() != S->getCatchStmt(I))
6521 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006522 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006523 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006524
Douglas Gregor306de2f2010-04-22 23:59:56 +00006525 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006526 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006527 if (S->getFinallyStmt()) {
6528 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6529 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006531 }
6532
6533 // If nothing changed, just retain this statement.
6534 if (!getDerived().AlwaysRebuild() &&
6535 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006536 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006537 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006538 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregor306de2f2010-04-22 23:59:56 +00006540 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006541 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006542 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006543}
Mike Stump11289f42009-09-09 15:08:12 +00006544
Douglas Gregorebe10102009-08-20 07:17:43 +00006545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006546StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006547TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006548 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006549 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006550 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006551 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006552 if (FromVar->getTypeSourceInfo()) {
6553 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6554 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006555 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006557
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006558 QualType T;
6559 if (TSInfo)
6560 T = TSInfo->getType();
6561 else {
6562 T = getDerived().TransformType(FromVar->getType());
6563 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006564 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006566
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006567 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6568 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006571
John McCalldadc5752010-08-24 06:29:42 +00006572 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006573 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006575
6576 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006577 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006578 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006579}
Mike Stump11289f42009-09-09 15:08:12 +00006580
Douglas Gregorebe10102009-08-20 07:17:43 +00006581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006582StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006583TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006584 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006585 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006586 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006587 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006588
Douglas Gregor306de2f2010-04-22 23:59:56 +00006589 // If nothing changed, just retain this statement.
6590 if (!getDerived().AlwaysRebuild() &&
6591 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006592 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006593
6594 // Build a new statement.
6595 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006596 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006597}
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregorebe10102009-08-20 07:17:43 +00006599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006600StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006601TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006602 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006603 if (S->getThrowExpr()) {
6604 Operand = getDerived().TransformExpr(S->getThrowExpr());
6605 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006608
Douglas Gregor2900c162010-04-22 21:44:01 +00006609 if (!getDerived().AlwaysRebuild() &&
6610 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006611 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006612
John McCallb268a282010-08-23 23:25:46 +00006613 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006614}
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregorebe10102009-08-20 07:17:43 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006618TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006619 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006620 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006621 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006622 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006623 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006624 Object =
6625 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6626 Object.get());
6627 if (Object.isInvalid())
6628 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006629
Douglas Gregor6148de72010-04-22 22:01:21 +00006630 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006631 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006632 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006634
Douglas Gregor6148de72010-04-22 22:01:21 +00006635 // If nothing change, just retain the current statement.
6636 if (!getDerived().AlwaysRebuild() &&
6637 Object.get() == S->getSynchExpr() &&
6638 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006639 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006640
6641 // Build a new statement.
6642 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006643 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006644}
6645
6646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006647StmtResult
John McCall31168b02011-06-15 23:02:42 +00006648TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6649 ObjCAutoreleasePoolStmt *S) {
6650 // Transform the body.
6651 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6652 if (Body.isInvalid())
6653 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006654
John McCall31168b02011-06-15 23:02:42 +00006655 // If nothing changed, just retain this statement.
6656 if (!getDerived().AlwaysRebuild() &&
6657 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006658 return S;
John McCall31168b02011-06-15 23:02:42 +00006659
6660 // Build a new statement.
6661 return getDerived().RebuildObjCAutoreleasePoolStmt(
6662 S->getAtLoc(), Body.get());
6663}
6664
6665template<typename Derived>
6666StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006667TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006668 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006669 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006670 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006671 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006673
Douglas Gregorf68a5082010-04-22 23:10:45 +00006674 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006675 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006676 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006677 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006678
Douglas Gregorf68a5082010-04-22 23:10:45 +00006679 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006680 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006681 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006682 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006683
Douglas Gregorf68a5082010-04-22 23:10:45 +00006684 // If nothing changed, just retain this statement.
6685 if (!getDerived().AlwaysRebuild() &&
6686 Element.get() == S->getElement() &&
6687 Collection.get() == S->getCollection() &&
6688 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006689 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006690
Douglas Gregorf68a5082010-04-22 23:10:45 +00006691 // Build a new statement.
6692 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006693 Element.get(),
6694 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006695 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006696 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006697}
6698
David Majnemer5f7efef2013-10-15 09:50:08 +00006699template <typename Derived>
6700StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006701 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006702 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006703 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6704 TypeSourceInfo *T =
6705 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006706 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006707 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006708
David Majnemer5f7efef2013-10-15 09:50:08 +00006709 Var = getDerived().RebuildExceptionDecl(
6710 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6711 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006712 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006713 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006714 }
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregorebe10102009-08-20 07:17:43 +00006716 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006717 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006718 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006719 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006720
David Majnemer5f7efef2013-10-15 09:50:08 +00006721 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006722 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006723 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006724
David Majnemer5f7efef2013-10-15 09:50:08 +00006725 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006726}
Mike Stump11289f42009-09-09 15:08:12 +00006727
David Majnemer5f7efef2013-10-15 09:50:08 +00006728template <typename Derived>
6729StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006730 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006731 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006732 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregorebe10102009-08-20 07:17:43 +00006735 // Transform the handlers.
6736 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006737 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006738 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006739 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006740 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006742
Douglas Gregorebe10102009-08-20 07:17:43 +00006743 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006744 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006745 }
Mike Stump11289f42009-09-09 15:08:12 +00006746
David Majnemer5f7efef2013-10-15 09:50:08 +00006747 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006748 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006749 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006750
John McCallb268a282010-08-23 23:25:46 +00006751 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006752 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006753}
Mike Stump11289f42009-09-09 15:08:12 +00006754
Richard Smith02e85f32011-04-14 22:09:26 +00006755template<typename Derived>
6756StmtResult
6757TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6758 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6759 if (Range.isInvalid())
6760 return StmtError();
6761
6762 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6763 if (BeginEnd.isInvalid())
6764 return StmtError();
6765
6766 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6767 if (Cond.isInvalid())
6768 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006769 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006770 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006771 if (Cond.isInvalid())
6772 return StmtError();
6773 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006774 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006775
6776 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6777 if (Inc.isInvalid())
6778 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006779 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006780 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006781
6782 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6783 if (LoopVar.isInvalid())
6784 return StmtError();
6785
6786 StmtResult NewStmt = S;
6787 if (getDerived().AlwaysRebuild() ||
6788 Range.get() != S->getRangeStmt() ||
6789 BeginEnd.get() != S->getBeginEndStmt() ||
6790 Cond.get() != S->getCond() ||
6791 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006792 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006793 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006794 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006795 S->getColonLoc(), Range.get(),
6796 BeginEnd.get(), Cond.get(),
6797 Inc.get(), LoopVar.get(),
6798 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006799 if (NewStmt.isInvalid())
6800 return StmtError();
6801 }
Richard Smith02e85f32011-04-14 22:09:26 +00006802
6803 StmtResult Body = getDerived().TransformStmt(S->getBody());
6804 if (Body.isInvalid())
6805 return StmtError();
6806
6807 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6808 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006809 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006810 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006811 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006812 S->getColonLoc(), Range.get(),
6813 BeginEnd.get(), Cond.get(),
6814 Inc.get(), LoopVar.get(),
6815 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006816 if (NewStmt.isInvalid())
6817 return StmtError();
6818 }
Richard Smith02e85f32011-04-14 22:09:26 +00006819
6820 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006821 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006822
6823 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6824}
6825
John Wiegley1c0675e2011-04-28 01:08:34 +00006826template<typename Derived>
6827StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006828TreeTransform<Derived>::TransformMSDependentExistsStmt(
6829 MSDependentExistsStmt *S) {
6830 // Transform the nested-name-specifier, if any.
6831 NestedNameSpecifierLoc QualifierLoc;
6832 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006833 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006834 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6835 if (!QualifierLoc)
6836 return StmtError();
6837 }
6838
6839 // Transform the declaration name.
6840 DeclarationNameInfo NameInfo = S->getNameInfo();
6841 if (NameInfo.getName()) {
6842 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6843 if (!NameInfo.getName())
6844 return StmtError();
6845 }
6846
6847 // Check whether anything changed.
6848 if (!getDerived().AlwaysRebuild() &&
6849 QualifierLoc == S->getQualifierLoc() &&
6850 NameInfo.getName() == S->getNameInfo().getName())
6851 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006852
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006853 // Determine whether this name exists, if we can.
6854 CXXScopeSpec SS;
6855 SS.Adopt(QualifierLoc);
6856 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006857 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006858 case Sema::IER_Exists:
6859 if (S->isIfExists())
6860 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006861
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006862 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6863
6864 case Sema::IER_DoesNotExist:
6865 if (S->isIfNotExists())
6866 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006867
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006868 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006869
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006870 case Sema::IER_Dependent:
6871 Dependent = true;
6872 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006873
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006874 case Sema::IER_Error:
6875 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006877
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006878 // We need to continue with the instantiation, so do so now.
6879 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6880 if (SubStmt.isInvalid())
6881 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006882
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006883 // If we have resolved the name, just transform to the substatement.
6884 if (!Dependent)
6885 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006886
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006887 // The name is still dependent, so build a dependent expression again.
6888 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6889 S->isIfExists(),
6890 QualifierLoc,
6891 NameInfo,
6892 SubStmt.get());
6893}
6894
6895template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006896ExprResult
6897TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6898 NestedNameSpecifierLoc QualifierLoc;
6899 if (E->getQualifierLoc()) {
6900 QualifierLoc
6901 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6902 if (!QualifierLoc)
6903 return ExprError();
6904 }
6905
6906 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6907 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6908 if (!PD)
6909 return ExprError();
6910
6911 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6912 if (Base.isInvalid())
6913 return ExprError();
6914
6915 return new (SemaRef.getASTContext())
6916 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6917 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6918 QualifierLoc, E->getMemberLoc());
6919}
6920
David Majnemerfad8f482013-10-15 09:33:02 +00006921template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00006922ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
6923 MSPropertySubscriptExpr *E) {
6924 auto BaseRes = getDerived().TransformExpr(E->getBase());
6925 if (BaseRes.isInvalid())
6926 return ExprError();
6927 auto IdxRes = getDerived().TransformExpr(E->getIdx());
6928 if (IdxRes.isInvalid())
6929 return ExprError();
6930
6931 if (!getDerived().AlwaysRebuild() &&
6932 BaseRes.get() == E->getBase() &&
6933 IdxRes.get() == E->getIdx())
6934 return E;
6935
6936 return getDerived().RebuildArraySubscriptExpr(
6937 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
6938}
6939
6940template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00006941StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006942 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006943 if (TryBlock.isInvalid())
6944 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006945
6946 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006947 if (Handler.isInvalid())
6948 return StmtError();
6949
David Majnemerfad8f482013-10-15 09:33:02 +00006950 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6951 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006952 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006953
Warren Huntf6be4cb2014-07-25 20:52:51 +00006954 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6955 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006956}
6957
David Majnemerfad8f482013-10-15 09:33:02 +00006958template <typename Derived>
6959StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006960 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006961 if (Block.isInvalid())
6962 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006963
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006964 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006965}
6966
David Majnemerfad8f482013-10-15 09:33:02 +00006967template <typename Derived>
6968StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006969 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006970 if (FilterExpr.isInvalid())
6971 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006972
David Majnemer7e755502013-10-15 09:30:14 +00006973 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006974 if (Block.isInvalid())
6975 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006976
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006977 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6978 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006979}
6980
David Majnemerfad8f482013-10-15 09:33:02 +00006981template <typename Derived>
6982StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6983 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006984 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6985 else
6986 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6987}
6988
Nico Weber9b982072014-07-07 00:12:30 +00006989template<typename Derived>
6990StmtResult
6991TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6992 return S;
6993}
6994
Alexander Musman64d33f12014-06-04 07:53:32 +00006995//===----------------------------------------------------------------------===//
6996// OpenMP directive transformation
6997//===----------------------------------------------------------------------===//
6998template <typename Derived>
6999StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7000 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007001
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007002 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007003 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007004 ArrayRef<OMPClause *> Clauses = D->clauses();
7005 TClauses.reserve(Clauses.size());
7006 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7007 I != E; ++I) {
7008 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007009 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007010 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007011 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007012 if (Clause)
7013 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007014 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007015 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007016 }
7017 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007018 StmtResult AssociatedStmt;
7019 if (D->hasAssociatedStmt()) {
7020 if (!D->getAssociatedStmt()) {
7021 return StmtError();
7022 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007023 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7024 /*CurScope=*/nullptr);
7025 StmtResult Body;
7026 {
7027 Sema::CompoundScopeRAII CompoundScope(getSema());
7028 Body = getDerived().TransformStmt(
7029 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7030 }
7031 AssociatedStmt =
7032 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007033 if (AssociatedStmt.isInvalid()) {
7034 return StmtError();
7035 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007036 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007037 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007038 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007039 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007040
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007041 // Transform directive name for 'omp critical' directive.
7042 DeclarationNameInfo DirName;
7043 if (D->getDirectiveKind() == OMPD_critical) {
7044 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7045 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7046 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007047 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7048 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7049 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007050 } else if (D->getDirectiveKind() == OMPD_cancel) {
7051 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007052 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007053
Alexander Musman64d33f12014-06-04 07:53:32 +00007054 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007055 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7056 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007057}
7058
Alexander Musman64d33f12014-06-04 07:53:32 +00007059template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007060StmtResult
7061TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7062 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007063 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7064 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7067 return Res;
7068}
7069
Alexander Musman64d33f12014-06-04 07:53:32 +00007070template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007071StmtResult
7072TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7073 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007074 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7075 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007078 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007079}
7080
Alexey Bataevf29276e2014-06-18 04:14:57 +00007081template <typename Derived>
7082StmtResult
7083TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7084 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007085 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7086 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7089 return Res;
7090}
7091
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007092template <typename Derived>
7093StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007094TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7095 DeclarationNameInfo DirName;
7096 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7097 D->getLocStart());
7098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7100 return Res;
7101}
7102
7103template <typename Derived>
7104StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007105TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7106 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007107 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7108 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7111 return Res;
7112}
7113
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007114template <typename Derived>
7115StmtResult
7116TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7117 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007118 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7119 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7122 return Res;
7123}
7124
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007125template <typename Derived>
7126StmtResult
7127TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7128 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007129 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7130 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7133 return Res;
7134}
7135
Alexey Bataev4acb8592014-07-07 13:01:15 +00007136template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007137StmtResult
7138TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7139 DeclarationNameInfo DirName;
7140 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7141 D->getLocStart());
7142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7144 return Res;
7145}
7146
7147template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007148StmtResult
7149TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7150 getDerived().getSema().StartOpenMPDSABlock(
7151 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7152 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7153 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7154 return Res;
7155}
7156
7157template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007158StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7159 OMPParallelForDirective *D) {
7160 DeclarationNameInfo DirName;
7161 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7162 nullptr, D->getLocStart());
7163 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7164 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7165 return Res;
7166}
7167
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007168template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007169StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7170 OMPParallelForSimdDirective *D) {
7171 DeclarationNameInfo DirName;
7172 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7173 nullptr, D->getLocStart());
7174 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7175 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7176 return Res;
7177}
7178
7179template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007180StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7181 OMPParallelSectionsDirective *D) {
7182 DeclarationNameInfo DirName;
7183 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7184 nullptr, D->getLocStart());
7185 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7186 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7187 return Res;
7188}
7189
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007190template <typename Derived>
7191StmtResult
7192TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7193 DeclarationNameInfo DirName;
7194 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7195 D->getLocStart());
7196 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7197 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7198 return Res;
7199}
7200
Alexey Bataev68446b72014-07-18 07:47:19 +00007201template <typename Derived>
7202StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7203 OMPTaskyieldDirective *D) {
7204 DeclarationNameInfo DirName;
7205 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7206 D->getLocStart());
7207 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7209 return Res;
7210}
7211
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007212template <typename Derived>
7213StmtResult
7214TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7215 DeclarationNameInfo DirName;
7216 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7217 D->getLocStart());
7218 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7219 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7220 return Res;
7221}
7222
Alexey Bataev2df347a2014-07-18 10:17:07 +00007223template <typename Derived>
7224StmtResult
7225TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7226 DeclarationNameInfo DirName;
7227 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7228 D->getLocStart());
7229 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7230 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7231 return Res;
7232}
7233
Alexey Bataev6125da92014-07-21 11:26:11 +00007234template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007235StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7236 OMPTaskgroupDirective *D) {
7237 DeclarationNameInfo DirName;
7238 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7239 D->getLocStart());
7240 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7241 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7242 return Res;
7243}
7244
7245template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007246StmtResult
7247TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7248 DeclarationNameInfo DirName;
7249 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7250 D->getLocStart());
7251 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7252 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7253 return Res;
7254}
7255
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007256template <typename Derived>
7257StmtResult
7258TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7259 DeclarationNameInfo DirName;
7260 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7261 D->getLocStart());
7262 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7263 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7264 return Res;
7265}
7266
Alexey Bataev0162e452014-07-22 10:10:35 +00007267template <typename Derived>
7268StmtResult
7269TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7270 DeclarationNameInfo DirName;
7271 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7272 D->getLocStart());
7273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7275 return Res;
7276}
7277
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007278template <typename Derived>
7279StmtResult
7280TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7281 DeclarationNameInfo DirName;
7282 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7283 D->getLocStart());
7284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7286 return Res;
7287}
7288
Alexey Bataev13314bf2014-10-09 04:18:56 +00007289template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007290StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7291 OMPTargetDataDirective *D) {
7292 DeclarationNameInfo DirName;
7293 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7294 D->getLocStart());
7295 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7296 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7297 return Res;
7298}
7299
7300template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007301StmtResult
7302TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7303 DeclarationNameInfo DirName;
7304 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7305 D->getLocStart());
7306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7308 return Res;
7309}
7310
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007311template <typename Derived>
7312StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7313 OMPCancellationPointDirective *D) {
7314 DeclarationNameInfo DirName;
7315 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7316 nullptr, D->getLocStart());
7317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7319 return Res;
7320}
7321
Alexey Bataev80909872015-07-02 11:25:17 +00007322template <typename Derived>
7323StmtResult
7324TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7325 DeclarationNameInfo DirName;
7326 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7327 D->getLocStart());
7328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7329 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7330 return Res;
7331}
7332
Alexander Musman64d33f12014-06-04 07:53:32 +00007333//===----------------------------------------------------------------------===//
7334// OpenMP clause transformation
7335//===----------------------------------------------------------------------===//
7336template <typename Derived>
7337OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007338 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7339 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007340 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007341 return getDerived().RebuildOMPIfClause(
7342 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7343 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007344}
7345
Alexander Musman64d33f12014-06-04 07:53:32 +00007346template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007347OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7348 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7349 if (Cond.isInvalid())
7350 return nullptr;
7351 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7352 C->getLParenLoc(), C->getLocEnd());
7353}
7354
7355template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007356OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007357TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7358 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7359 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007360 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007361 return getDerived().RebuildOMPNumThreadsClause(
7362 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007363}
7364
Alexey Bataev62c87d22014-03-21 04:51:18 +00007365template <typename Derived>
7366OMPClause *
7367TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7368 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7369 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007370 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007371 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007372 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007373}
7374
Alexander Musman8bd31e62014-05-27 15:12:19 +00007375template <typename Derived>
7376OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007377TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7378 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7379 if (E.isInvalid())
7380 return nullptr;
7381 return getDerived().RebuildOMPSimdlenClause(
7382 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7383}
7384
7385template <typename Derived>
7386OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007387TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7388 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7389 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007390 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007391 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007392 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007393}
7394
Alexander Musman64d33f12014-06-04 07:53:32 +00007395template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007396OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007397TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007398 return getDerived().RebuildOMPDefaultClause(
7399 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7400 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007401}
7402
Alexander Musman64d33f12014-06-04 07:53:32 +00007403template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007404OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007405TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007406 return getDerived().RebuildOMPProcBindClause(
7407 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7408 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007409}
7410
Alexander Musman64d33f12014-06-04 07:53:32 +00007411template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007412OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007413TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7414 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7415 if (E.isInvalid())
7416 return nullptr;
7417 return getDerived().RebuildOMPScheduleClause(
7418 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7419 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7420}
7421
7422template <typename Derived>
7423OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007424TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007425 ExprResult E;
7426 if (auto *Num = C->getNumForLoops()) {
7427 E = getDerived().TransformExpr(Num);
7428 if (E.isInvalid())
7429 return nullptr;
7430 }
7431 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7432 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007433}
7434
7435template <typename Derived>
7436OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007437TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7438 // No need to rebuild this clause, no template-dependent parameters.
7439 return C;
7440}
7441
7442template <typename Derived>
7443OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007444TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7445 // No need to rebuild this clause, no template-dependent parameters.
7446 return C;
7447}
7448
7449template <typename Derived>
7450OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007451TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7452 // No need to rebuild this clause, no template-dependent parameters.
7453 return C;
7454}
7455
7456template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007457OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7458 // No need to rebuild this clause, no template-dependent parameters.
7459 return C;
7460}
7461
7462template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007463OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7464 // No need to rebuild this clause, no template-dependent parameters.
7465 return C;
7466}
7467
7468template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007469OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007470TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7471 // No need to rebuild this clause, no template-dependent parameters.
7472 return C;
7473}
7474
7475template <typename Derived>
7476OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007477TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7478 // No need to rebuild this clause, no template-dependent parameters.
7479 return C;
7480}
7481
7482template <typename Derived>
7483OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007484TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7485 // No need to rebuild this clause, no template-dependent parameters.
7486 return C;
7487}
7488
7489template <typename Derived>
7490OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007491TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7492 // No need to rebuild this clause, no template-dependent parameters.
7493 return C;
7494}
7495
7496template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007497OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7498 // No need to rebuild this clause, no template-dependent parameters.
7499 return C;
7500}
7501
7502template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007503OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007504TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007505 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007506 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007507 for (auto *VE : C->varlists()) {
7508 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007509 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007510 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007511 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007512 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007513 return getDerived().RebuildOMPPrivateClause(
7514 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007515}
7516
Alexander Musman64d33f12014-06-04 07:53:32 +00007517template <typename Derived>
7518OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7519 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007520 llvm::SmallVector<Expr *, 16> Vars;
7521 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007522 for (auto *VE : C->varlists()) {
7523 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007524 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007525 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007526 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007527 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007528 return getDerived().RebuildOMPFirstprivateClause(
7529 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007530}
7531
Alexander Musman64d33f12014-06-04 07:53:32 +00007532template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007533OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007534TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *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().RebuildOMPLastprivateClause(
7544 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7545}
7546
7547template <typename Derived>
7548OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007549TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7550 llvm::SmallVector<Expr *, 16> Vars;
7551 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007552 for (auto *VE : C->varlists()) {
7553 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007554 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007555 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007556 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007557 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007558 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7559 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007560}
7561
Alexander Musman64d33f12014-06-04 07:53:32 +00007562template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007563OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007564TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7565 llvm::SmallVector<Expr *, 16> Vars;
7566 Vars.reserve(C->varlist_size());
7567 for (auto *VE : C->varlists()) {
7568 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7569 if (EVar.isInvalid())
7570 return nullptr;
7571 Vars.push_back(EVar.get());
7572 }
7573 CXXScopeSpec ReductionIdScopeSpec;
7574 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7575
7576 DeclarationNameInfo NameInfo = C->getNameInfo();
7577 if (NameInfo.getName()) {
7578 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7579 if (!NameInfo.getName())
7580 return nullptr;
7581 }
7582 return getDerived().RebuildOMPReductionClause(
7583 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7584 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7585}
7586
7587template <typename Derived>
7588OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007589TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7590 llvm::SmallVector<Expr *, 16> Vars;
7591 Vars.reserve(C->varlist_size());
7592 for (auto *VE : C->varlists()) {
7593 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7594 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007595 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007596 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007597 }
7598 ExprResult Step = getDerived().TransformExpr(C->getStep());
7599 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007600 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007601 return getDerived().RebuildOMPLinearClause(
7602 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7603 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007604}
7605
Alexander Musman64d33f12014-06-04 07:53:32 +00007606template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007607OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007608TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7609 llvm::SmallVector<Expr *, 16> Vars;
7610 Vars.reserve(C->varlist_size());
7611 for (auto *VE : C->varlists()) {
7612 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7613 if (EVar.isInvalid())
7614 return nullptr;
7615 Vars.push_back(EVar.get());
7616 }
7617 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7618 if (Alignment.isInvalid())
7619 return nullptr;
7620 return getDerived().RebuildOMPAlignedClause(
7621 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7622 C->getColonLoc(), C->getLocEnd());
7623}
7624
Alexander Musman64d33f12014-06-04 07:53:32 +00007625template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007626OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007627TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7628 llvm::SmallVector<Expr *, 16> Vars;
7629 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007630 for (auto *VE : C->varlists()) {
7631 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007632 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007633 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007634 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007635 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007636 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7637 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007638}
7639
Alexey Bataevbae9a792014-06-27 10:37:06 +00007640template <typename Derived>
7641OMPClause *
7642TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7643 llvm::SmallVector<Expr *, 16> Vars;
7644 Vars.reserve(C->varlist_size());
7645 for (auto *VE : C->varlists()) {
7646 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7647 if (EVar.isInvalid())
7648 return nullptr;
7649 Vars.push_back(EVar.get());
7650 }
7651 return getDerived().RebuildOMPCopyprivateClause(
7652 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7653}
7654
Alexey Bataev6125da92014-07-21 11:26:11 +00007655template <typename Derived>
7656OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7657 llvm::SmallVector<Expr *, 16> Vars;
7658 Vars.reserve(C->varlist_size());
7659 for (auto *VE : C->varlists()) {
7660 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7661 if (EVar.isInvalid())
7662 return nullptr;
7663 Vars.push_back(EVar.get());
7664 }
7665 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7666 C->getLParenLoc(), C->getLocEnd());
7667}
7668
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007669template <typename Derived>
7670OMPClause *
7671TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7672 llvm::SmallVector<Expr *, 16> Vars;
7673 Vars.reserve(C->varlist_size());
7674 for (auto *VE : C->varlists()) {
7675 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7676 if (EVar.isInvalid())
7677 return nullptr;
7678 Vars.push_back(EVar.get());
7679 }
7680 return getDerived().RebuildOMPDependClause(
7681 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7682 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7683}
7684
Michael Wonge710d542015-08-07 16:16:36 +00007685template <typename Derived>
7686OMPClause *
7687TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7688 ExprResult E = getDerived().TransformExpr(C->getDevice());
7689 if (E.isInvalid())
7690 return nullptr;
7691 return getDerived().RebuildOMPDeviceClause(
7692 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7693}
7694
Kelvin Li0bff7af2015-11-23 05:32:03 +00007695template <typename Derived>
7696OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7697 llvm::SmallVector<Expr *, 16> Vars;
7698 Vars.reserve(C->varlist_size());
7699 for (auto *VE : C->varlists()) {
7700 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7701 if (EVar.isInvalid())
7702 return nullptr;
7703 Vars.push_back(EVar.get());
7704 }
7705 return getDerived().RebuildOMPMapClause(
7706 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7707 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7708 C->getLocEnd());
7709}
7710
Kelvin Li099bb8c2015-11-24 20:50:12 +00007711template <typename Derived>
7712OMPClause *
7713TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7714 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7715 if (E.isInvalid())
7716 return nullptr;
7717 return getDerived().RebuildOMPNumTeamsClause(
7718 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7719}
7720
Douglas Gregorebe10102009-08-20 07:17:43 +00007721//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007722// Expression transformation
7723//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007726TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007727 if (!E->isTypeDependent())
7728 return E;
7729
7730 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7731 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007732}
Mike Stump11289f42009-09-09 15:08:12 +00007733
7734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007736TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007737 NestedNameSpecifierLoc QualifierLoc;
7738 if (E->getQualifierLoc()) {
7739 QualifierLoc
7740 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7741 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007742 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007743 }
John McCallce546572009-12-08 09:08:17 +00007744
7745 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007746 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7747 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007748 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007750
John McCall815039a2010-08-17 21:27:17 +00007751 DeclarationNameInfo NameInfo = E->getNameInfo();
7752 if (NameInfo.getName()) {
7753 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7754 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007755 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007756 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007757
7758 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007759 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007760 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007761 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007762 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007763
7764 // Mark it referenced in the new context regardless.
7765 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007766 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007767
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007768 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007769 }
John McCallce546572009-12-08 09:08:17 +00007770
Craig Topperc3ec1492014-05-26 06:22:03 +00007771 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007772 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007773 TemplateArgs = &TransArgs;
7774 TransArgs.setLAngleLoc(E->getLAngleLoc());
7775 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007776 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7777 E->getNumTemplateArgs(),
7778 TransArgs))
7779 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007780 }
7781
Chad Rosier1dcde962012-08-08 18:46:20 +00007782 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007783 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007784}
Mike Stump11289f42009-09-09 15:08:12 +00007785
Douglas Gregora16548e2009-08-11 05:31:07 +00007786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007788TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007789 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007790}
Mike Stump11289f42009-09-09 15:08:12 +00007791
Douglas Gregora16548e2009-08-11 05:31:07 +00007792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007794TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007795 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007796}
Mike Stump11289f42009-09-09 15:08:12 +00007797
Douglas Gregora16548e2009-08-11 05:31:07 +00007798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007800TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007801 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007802}
Mike Stump11289f42009-09-09 15:08:12 +00007803
Douglas Gregora16548e2009-08-11 05:31:07 +00007804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007806TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007807 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007808}
Mike Stump11289f42009-09-09 15:08:12 +00007809
Douglas Gregora16548e2009-08-11 05:31:07 +00007810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007812TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007813 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007814}
7815
7816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007817ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007818TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007819 if (FunctionDecl *FD = E->getDirectCallee())
7820 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007821 return SemaRef.MaybeBindToTemporary(E);
7822}
7823
7824template<typename Derived>
7825ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007826TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7827 ExprResult ControllingExpr =
7828 getDerived().TransformExpr(E->getControllingExpr());
7829 if (ControllingExpr.isInvalid())
7830 return ExprError();
7831
Chris Lattner01cf8db2011-07-20 06:58:45 +00007832 SmallVector<Expr *, 4> AssocExprs;
7833 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007834 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7835 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7836 if (TS) {
7837 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7838 if (!AssocType)
7839 return ExprError();
7840 AssocTypes.push_back(AssocType);
7841 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007842 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007843 }
7844
7845 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7846 if (AssocExpr.isInvalid())
7847 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007848 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007849 }
7850
7851 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7852 E->getDefaultLoc(),
7853 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007854 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007855 AssocTypes,
7856 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007857}
7858
7859template<typename Derived>
7860ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007861TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007862 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007867 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007868
John McCallb268a282010-08-23 23:25:46 +00007869 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007870 E->getRParen());
7871}
7872
Richard Smithdb2630f2012-10-21 03:28:35 +00007873/// \brief The operand of a unary address-of operator has special rules: it's
7874/// allowed to refer to a non-static member of a class even if there's no 'this'
7875/// object available.
7876template<typename Derived>
7877ExprResult
7878TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7879 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007880 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007881 else
7882 return getDerived().TransformExpr(E);
7883}
7884
Mike Stump11289f42009-09-09 15:08:12 +00007885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007887TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007888 ExprResult SubExpr;
7889 if (E->getOpcode() == UO_AddrOf)
7890 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7891 else
7892 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007893 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007895
Douglas Gregora16548e2009-08-11 05:31:07 +00007896 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007897 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007898
Douglas Gregora16548e2009-08-11 05:31:07 +00007899 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7900 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007901 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007902}
Mike Stump11289f42009-09-09 15:08:12 +00007903
Douglas Gregora16548e2009-08-11 05:31:07 +00007904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007905ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007906TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7907 // Transform the type.
7908 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7909 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007910 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007911
Douglas Gregor882211c2010-04-28 22:16:22 +00007912 // Transform all of the components into components similar to what the
7913 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007914 // FIXME: It would be slightly more efficient in the non-dependent case to
7915 // just map FieldDecls, rather than requiring the rebuilder to look for
7916 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007917 // template code that we don't care.
7918 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007919 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007920 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007921 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007922 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7923 const Node &ON = E->getComponent(I);
7924 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007925 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007926 Comp.LocStart = ON.getSourceRange().getBegin();
7927 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007928 switch (ON.getKind()) {
7929 case Node::Array: {
7930 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007931 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007932 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007933 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007934
Douglas Gregor882211c2010-04-28 22:16:22 +00007935 ExprChanged = ExprChanged || Index.get() != FromIndex;
7936 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007937 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007938 break;
7939 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007940
Douglas Gregor882211c2010-04-28 22:16:22 +00007941 case Node::Field:
7942 case Node::Identifier:
7943 Comp.isBrackets = false;
7944 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007945 if (!Comp.U.IdentInfo)
7946 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007947
Douglas Gregor882211c2010-04-28 22:16:22 +00007948 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007949
Douglas Gregord1702062010-04-29 00:18:15 +00007950 case Node::Base:
7951 // Will be recomputed during the rebuild.
7952 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007954
Douglas Gregor882211c2010-04-28 22:16:22 +00007955 Components.push_back(Comp);
7956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007957
Douglas Gregor882211c2010-04-28 22:16:22 +00007958 // If nothing changed, retain the existing expression.
7959 if (!getDerived().AlwaysRebuild() &&
7960 Type == E->getTypeSourceInfo() &&
7961 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007962 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007963
Douglas Gregor882211c2010-04-28 22:16:22 +00007964 // Build a new offsetof expression.
7965 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00007966 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00007967}
7968
7969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007970ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007971TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00007972 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00007973 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007974 return E;
John McCall8d69a212010-11-15 23:31:06 +00007975}
7976
7977template<typename Derived>
7978ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007979TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7980 return E;
7981}
7982
7983template<typename Derived>
7984ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007985TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007986 // Rebuild the syntactic form. The original syntactic form has
7987 // opaque-value expressions in it, so strip those away and rebuild
7988 // the result. This is a really awful way of doing this, but the
7989 // better solution (rebuilding the semantic expressions and
7990 // rebinding OVEs as necessary) doesn't work; we'd need
7991 // TreeTransform to not strip away implicit conversions.
7992 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7993 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007994 if (result.isInvalid()) return ExprError();
7995
7996 // If that gives us a pseudo-object result back, the pseudo-object
7997 // expression must have been an lvalue-to-rvalue conversion which we
7998 // should reapply.
7999 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008000 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008001
8002 return result;
8003}
8004
8005template<typename Derived>
8006ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008007TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8008 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008009 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008010 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008011
John McCallbcd03502009-12-07 02:54:59 +00008012 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008013 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008015
John McCall4c98fd82009-11-04 07:28:41 +00008016 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008017 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008018
Peter Collingbournee190dee2011-03-11 19:24:49 +00008019 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8020 E->getKind(),
8021 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008022 }
Mike Stump11289f42009-09-09 15:08:12 +00008023
Eli Friedmane4f22df2012-02-29 04:03:55 +00008024 // C++0x [expr.sizeof]p1:
8025 // The operand is either an expression, which is an unevaluated operand
8026 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008027 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8028 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008029
Reid Kleckner32506ed2014-06-12 23:03:48 +00008030 // Try to recover if we have something like sizeof(T::X) where X is a type.
8031 // Notably, there must be *exactly* one set of parens if X is a type.
8032 TypeSourceInfo *RecoveryTSI = nullptr;
8033 ExprResult SubExpr;
8034 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8035 if (auto *DRE =
8036 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8037 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8038 PE, DRE, false, &RecoveryTSI);
8039 else
8040 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8041
8042 if (RecoveryTSI) {
8043 return getDerived().RebuildUnaryExprOrTypeTrait(
8044 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8045 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008047
Eli Friedmane4f22df2012-02-29 04:03:55 +00008048 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008049 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008050
Peter Collingbournee190dee2011-03-11 19:24:49 +00008051 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8052 E->getOperatorLoc(),
8053 E->getKind(),
8054 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008055}
Mike Stump11289f42009-09-09 15:08:12 +00008056
Douglas Gregora16548e2009-08-11 05:31:07 +00008057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008059TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008060 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008062 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008063
John McCalldadc5752010-08-24 06:29:42 +00008064 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008065 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008067
8068
Douglas Gregora16548e2009-08-11 05:31:07 +00008069 if (!getDerived().AlwaysRebuild() &&
8070 LHS.get() == E->getLHS() &&
8071 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008072 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008073
John McCallb268a282010-08-23 23:25:46 +00008074 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008075 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008076 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008077 E->getRBracketLoc());
8078}
Mike Stump11289f42009-09-09 15:08:12 +00008079
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008080template <typename Derived>
8081ExprResult
8082TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8083 ExprResult Base = getDerived().TransformExpr(E->getBase());
8084 if (Base.isInvalid())
8085 return ExprError();
8086
8087 ExprResult LowerBound;
8088 if (E->getLowerBound()) {
8089 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8090 if (LowerBound.isInvalid())
8091 return ExprError();
8092 }
8093
8094 ExprResult Length;
8095 if (E->getLength()) {
8096 Length = getDerived().TransformExpr(E->getLength());
8097 if (Length.isInvalid())
8098 return ExprError();
8099 }
8100
8101 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8102 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8103 return E;
8104
8105 return getDerived().RebuildOMPArraySectionExpr(
8106 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8107 Length.get(), E->getRBracketLoc());
8108}
8109
Mike Stump11289f42009-09-09 15:08:12 +00008110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008112TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008113 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008114 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008117
8118 // Transform arguments.
8119 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008120 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008121 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008122 &ArgChanged))
8123 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008124
Douglas Gregora16548e2009-08-11 05:31:07 +00008125 if (!getDerived().AlwaysRebuild() &&
8126 Callee.get() == E->getCallee() &&
8127 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008128 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008131 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008132 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008133 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008134 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 E->getRParenLoc());
8136}
Mike Stump11289f42009-09-09 15:08:12 +00008137
8138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008140TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008141 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008144
Douglas Gregorea972d32011-02-28 21:54:11 +00008145 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008146 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008147 QualifierLoc
8148 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008149
Douglas Gregorea972d32011-02-28 21:54:11 +00008150 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008151 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008152 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008153 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008154
Eli Friedman2cfcef62009-12-04 06:40:45 +00008155 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008156 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8157 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008158 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008160
John McCall16df1e52010-03-30 21:47:33 +00008161 NamedDecl *FoundDecl = E->getFoundDecl();
8162 if (FoundDecl == E->getMemberDecl()) {
8163 FoundDecl = Member;
8164 } else {
8165 FoundDecl = cast_or_null<NamedDecl>(
8166 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8167 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008169 }
8170
Douglas Gregora16548e2009-08-11 05:31:07 +00008171 if (!getDerived().AlwaysRebuild() &&
8172 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008173 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008174 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008175 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008176 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008177
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008178 // Mark it referenced in the new context regardless.
8179 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008180 SemaRef.MarkMemberReferenced(E);
8181
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008182 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008183 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008184
John McCall6b51f282009-11-23 01:53:49 +00008185 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008186 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008187 TransArgs.setLAngleLoc(E->getLAngleLoc());
8188 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008189 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8190 E->getNumTemplateArgs(),
8191 TransArgs))
8192 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008194
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008196 SourceLocation FakeOperatorLoc =
8197 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008198
John McCall38836f02010-01-15 08:34:02 +00008199 // FIXME: to do this check properly, we will need to preserve the
8200 // first-qualifier-in-scope here, just in case we had a dependent
8201 // base (and therefore couldn't do the check) and a
8202 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008203 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008204
John McCallb268a282010-08-23 23:25:46 +00008205 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008207 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008208 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008209 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008210 Member,
John McCall16df1e52010-03-30 21:47:33 +00008211 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008212 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008213 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008214 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008215}
Mike Stump11289f42009-09-09 15:08:12 +00008216
Douglas Gregora16548e2009-08-11 05:31:07 +00008217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008219TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008220 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008223
John McCalldadc5752010-08-24 06:29:42 +00008224 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 if (!getDerived().AlwaysRebuild() &&
8229 LHS.get() == E->getLHS() &&
8230 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008231 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008232
Lang Hames5de91cc2012-10-02 04:45:10 +00008233 Sema::FPContractStateRAII FPContractState(getSema());
8234 getSema().FPFeatures.fp_contract = E->isFPContractable();
8235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008237 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008238}
8239
Mike Stump11289f42009-09-09 15:08:12 +00008240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008241ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008242TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008243 CompoundAssignOperator *E) {
8244 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008245}
Mike Stump11289f42009-09-09 15:08:12 +00008246
Douglas Gregora16548e2009-08-11 05:31:07 +00008247template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008248ExprResult TreeTransform<Derived>::
8249TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8250 // Just rebuild the common and RHS expressions and see whether we
8251 // get any changes.
8252
8253 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8254 if (commonExpr.isInvalid())
8255 return ExprError();
8256
8257 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8258 if (rhs.isInvalid())
8259 return ExprError();
8260
8261 if (!getDerived().AlwaysRebuild() &&
8262 commonExpr.get() == e->getCommon() &&
8263 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008264 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008265
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008266 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008267 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008268 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008269 e->getColonLoc(),
8270 rhs.get());
8271}
8272
8273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008275TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008276 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008279
John McCalldadc5752010-08-24 06:29:42 +00008280 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008281 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008283
John McCalldadc5752010-08-24 06:29:42 +00008284 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008285 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 if (!getDerived().AlwaysRebuild() &&
8289 Cond.get() == E->getCond() &&
8290 LHS.get() == E->getLHS() &&
8291 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008292 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008293
John McCallb268a282010-08-23 23:25:46 +00008294 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008295 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008296 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008297 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008298 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008299}
Mike Stump11289f42009-09-09 15:08:12 +00008300
8301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008303TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008304 // Implicit casts are eliminated during transformation, since they
8305 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008306 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008307}
Mike Stump11289f42009-09-09 15:08:12 +00008308
Douglas Gregora16548e2009-08-11 05:31:07 +00008309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008310ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008311TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008312 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8313 if (!Type)
8314 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008315
John McCalldadc5752010-08-24 06:29:42 +00008316 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008317 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008320
Douglas Gregora16548e2009-08-11 05:31:07 +00008321 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008322 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008323 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008324 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008325
John McCall97513962010-01-15 18:39:57 +00008326 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008327 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008329 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008330}
Mike Stump11289f42009-09-09 15:08:12 +00008331
Douglas Gregora16548e2009-08-11 05:31:07 +00008332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008334TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008335 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8336 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8337 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008339
John McCalldadc5752010-08-24 06:29:42 +00008340 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008343
Douglas Gregora16548e2009-08-11 05:31:07 +00008344 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008345 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008347 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008348
John McCall5d7aa7f2010-01-19 22:33:45 +00008349 // Note: the expression type doesn't necessarily match the
8350 // type-as-written, but that's okay, because it should always be
8351 // derivable from the initializer.
8352
John McCalle15bbff2010-01-18 19:35:47 +00008353 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008355 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008356}
Mike Stump11289f42009-09-09 15:08:12 +00008357
Douglas Gregora16548e2009-08-11 05:31:07 +00008358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008360TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008361 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008364
Douglas Gregora16548e2009-08-11 05:31:07 +00008365 if (!getDerived().AlwaysRebuild() &&
8366 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008367 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008368
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008370 SourceLocation FakeOperatorLoc =
8371 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008372 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008373 E->getAccessorLoc(),
8374 E->getAccessor());
8375}
Mike Stump11289f42009-09-09 15:08:12 +00008376
Douglas Gregora16548e2009-08-11 05:31:07 +00008377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008379TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008380 if (InitListExpr *Syntactic = E->getSyntacticForm())
8381 E = Syntactic;
8382
Douglas Gregora16548e2009-08-11 05:31:07 +00008383 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008384
Benjamin Kramerf0623432012-08-23 22:51:59 +00008385 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008386 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008387 Inits, &InitChanged))
8388 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008389
Richard Smith520449d2015-02-05 06:15:50 +00008390 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8391 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8392 // in some cases. We can't reuse it in general, because the syntactic and
8393 // semantic forms are linked, and we can't know that semantic form will
8394 // match even if the syntactic form does.
8395 }
Mike Stump11289f42009-09-09 15:08:12 +00008396
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008397 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008398 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008399}
Mike Stump11289f42009-09-09 15:08:12 +00008400
Douglas Gregora16548e2009-08-11 05:31:07 +00008401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008403TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008404 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008405
Douglas Gregorebe10102009-08-20 07:17:43 +00008406 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008407 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008410
Douglas Gregorebe10102009-08-20 07:17:43 +00008411 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008412 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008413 bool ExprChanged = false;
8414 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8415 DEnd = E->designators_end();
8416 D != DEnd; ++D) {
8417 if (D->isFieldDesignator()) {
8418 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8419 D->getDotLoc(),
8420 D->getFieldLoc()));
8421 continue;
8422 }
Mike Stump11289f42009-09-09 15:08:12 +00008423
Douglas Gregora16548e2009-08-11 05:31:07 +00008424 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008425 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008428
8429 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008431
Douglas Gregora16548e2009-08-11 05:31:07 +00008432 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008433 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 continue;
8435 }
Mike Stump11289f42009-09-09 15:08:12 +00008436
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008438 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008439 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8440 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008441 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008442
John McCalldadc5752010-08-24 06:29:42 +00008443 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008444 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008446
8447 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 End.get(),
8449 D->getLBracketLoc(),
8450 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008451
Douglas Gregora16548e2009-08-11 05:31:07 +00008452 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8453 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008454
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008455 ArrayExprs.push_back(Start.get());
8456 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008457 }
Mike Stump11289f42009-09-09 15:08:12 +00008458
Douglas Gregora16548e2009-08-11 05:31:07 +00008459 if (!getDerived().AlwaysRebuild() &&
8460 Init.get() == E->getInit() &&
8461 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008462 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008463
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008464 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008465 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008466 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008467}
Mike Stump11289f42009-09-09 15:08:12 +00008468
Yunzhong Gaocb779302015-06-10 00:27:52 +00008469// Seems that if TransformInitListExpr() only works on the syntactic form of an
8470// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8471template<typename Derived>
8472ExprResult
8473TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8474 DesignatedInitUpdateExpr *E) {
8475 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8476 "initializer");
8477 return ExprError();
8478}
8479
8480template<typename Derived>
8481ExprResult
8482TreeTransform<Derived>::TransformNoInitExpr(
8483 NoInitExpr *E) {
8484 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8485 return ExprError();
8486}
8487
Douglas Gregora16548e2009-08-11 05:31:07 +00008488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008489ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008490TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008491 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008492 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008493
Douglas Gregor3da3c062009-10-28 00:29:27 +00008494 // FIXME: Will we ever have proper type location here? Will we actually
8495 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008496 QualType T = getDerived().TransformType(E->getType());
8497 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008499
Douglas Gregora16548e2009-08-11 05:31:07 +00008500 if (!getDerived().AlwaysRebuild() &&
8501 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008502 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008503
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 return getDerived().RebuildImplicitValueInitExpr(T);
8505}
Mike Stump11289f42009-09-09 15:08:12 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008509TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008510 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8511 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008513
John McCalldadc5752010-08-24 06:29:42 +00008514 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008519 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008520 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008521 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008522
John McCallb268a282010-08-23 23:25:46 +00008523 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008524 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008525}
8526
8527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008529TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008531 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008532 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8533 &ArgumentChanged))
8534 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008537 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 E->getRParenLoc());
8539}
Mike Stump11289f42009-09-09 15:08:12 +00008540
Douglas Gregora16548e2009-08-11 05:31:07 +00008541/// \brief Transform an address-of-label expression.
8542///
8543/// By default, the transformation of an address-of-label expression always
8544/// rebuilds the expression, so that the label identifier can be resolved to
8545/// the corresponding label statement by semantic analysis.
8546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008548TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008549 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8550 E->getLabel());
8551 if (!LD)
8552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008555 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008556}
Mike Stump11289f42009-09-09 15:08:12 +00008557
8558template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008559ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008560TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008561 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008562 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008564 if (SubStmt.isInvalid()) {
8565 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008567 }
Mike Stump11289f42009-09-09 15:08:12 +00008568
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008570 SubStmt.get() == E->getSubStmt()) {
8571 // Calling this an 'error' is unintuitive, but it does the right thing.
8572 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008573 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008574 }
Mike Stump11289f42009-09-09 15:08:12 +00008575
8576 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008577 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 E->getRParenLoc());
8579}
Mike Stump11289f42009-09-09 15:08:12 +00008580
Douglas Gregora16548e2009-08-11 05:31:07 +00008581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008583TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008584 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008587
John McCalldadc5752010-08-24 06:29:42 +00008588 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008589 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008591
John McCalldadc5752010-08-24 06:29:42 +00008592 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008593 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008595
Douglas Gregora16548e2009-08-11 05:31:07 +00008596 if (!getDerived().AlwaysRebuild() &&
8597 Cond.get() == E->getCond() &&
8598 LHS.get() == E->getLHS() &&
8599 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008600 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008601
Douglas Gregora16548e2009-08-11 05:31:07 +00008602 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008603 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008604 E->getRParenLoc());
8605}
Mike Stump11289f42009-09-09 15:08:12 +00008606
Douglas Gregora16548e2009-08-11 05:31:07 +00008607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008609TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008610 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008611}
8612
8613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008615TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008616 switch (E->getOperator()) {
8617 case OO_New:
8618 case OO_Delete:
8619 case OO_Array_New:
8620 case OO_Array_Delete:
8621 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008622
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008623 case OO_Call: {
8624 // This is a call to an object's operator().
8625 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8626
8627 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008628 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008629 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008630 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008631
8632 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008633 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8634 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008635
8636 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008637 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008638 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008639 Args))
8640 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008641
John McCallb268a282010-08-23 23:25:46 +00008642 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008643 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008644 E->getLocEnd());
8645 }
8646
8647#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8648 case OO_##Name:
8649#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8650#include "clang/Basic/OperatorKinds.def"
8651 case OO_Subscript:
8652 // Handled below.
8653 break;
8654
8655 case OO_Conditional:
8656 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008657
8658 case OO_None:
8659 case NUM_OVERLOADED_OPERATORS:
8660 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008661 }
8662
John McCalldadc5752010-08-24 06:29:42 +00008663 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008666
Richard Smithdb2630f2012-10-21 03:28:35 +00008667 ExprResult First;
8668 if (E->getOperator() == OO_Amp)
8669 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8670 else
8671 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008673 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008674
John McCalldadc5752010-08-24 06:29:42 +00008675 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008676 if (E->getNumArgs() == 2) {
8677 Second = getDerived().TransformExpr(E->getArg(1));
8678 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008679 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008680 }
Mike Stump11289f42009-09-09 15:08:12 +00008681
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 if (!getDerived().AlwaysRebuild() &&
8683 Callee.get() == E->getCallee() &&
8684 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008685 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008686 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008687
Lang Hames5de91cc2012-10-02 04:45:10 +00008688 Sema::FPContractStateRAII FPContractState(getSema());
8689 getSema().FPFeatures.fp_contract = E->isFPContractable();
8690
Douglas Gregora16548e2009-08-11 05:31:07 +00008691 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8692 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008693 Callee.get(),
8694 First.get(),
8695 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008696}
Mike Stump11289f42009-09-09 15:08:12 +00008697
Douglas Gregora16548e2009-08-11 05:31:07 +00008698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008700TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8701 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008702}
Mike Stump11289f42009-09-09 15:08:12 +00008703
Douglas Gregora16548e2009-08-11 05:31:07 +00008704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008705ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008706TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8707 // Transform the callee.
8708 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8709 if (Callee.isInvalid())
8710 return ExprError();
8711
8712 // Transform exec config.
8713 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8714 if (EC.isInvalid())
8715 return ExprError();
8716
8717 // Transform arguments.
8718 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008719 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008720 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008721 &ArgChanged))
8722 return ExprError();
8723
8724 if (!getDerived().AlwaysRebuild() &&
8725 Callee.get() == E->getCallee() &&
8726 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008727 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008728
8729 // FIXME: Wrong source location information for the '('.
8730 SourceLocation FakeLParenLoc
8731 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8732 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008733 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008734 E->getRParenLoc(), EC.get());
8735}
8736
8737template<typename Derived>
8738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008739TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008740 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8741 if (!Type)
8742 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008743
John McCalldadc5752010-08-24 06:29:42 +00008744 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008745 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008748
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008750 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008751 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008752 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008753 return getDerived().RebuildCXXNamedCastExpr(
8754 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8755 Type, E->getAngleBrackets().getEnd(),
8756 // FIXME. this should be '(' location
8757 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008758}
Mike Stump11289f42009-09-09 15:08:12 +00008759
Douglas Gregora16548e2009-08-11 05:31:07 +00008760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008762TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8763 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008764}
Mike Stump11289f42009-09-09 15:08:12 +00008765
8766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008768TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8769 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008770}
8771
Douglas Gregora16548e2009-08-11 05:31:07 +00008772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008773ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008774TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008775 CXXReinterpretCastExpr *E) {
8776 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008777}
Mike Stump11289f42009-09-09 15:08:12 +00008778
Douglas Gregora16548e2009-08-11 05:31:07 +00008779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008781TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8782 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008783}
Mike Stump11289f42009-09-09 15:08:12 +00008784
Douglas Gregora16548e2009-08-11 05:31:07 +00008785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008786ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008787TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008788 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008789 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8790 if (!Type)
8791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008792
John McCalldadc5752010-08-24 06:29:42 +00008793 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008794 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008795 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008797
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008799 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008800 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008801 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008802
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008803 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008804 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008805 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008806 E->getRParenLoc());
8807}
Mike Stump11289f42009-09-09 15:08:12 +00008808
Douglas Gregora16548e2009-08-11 05:31:07 +00008809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008811TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008813 TypeSourceInfo *TInfo
8814 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8815 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008817
Douglas Gregora16548e2009-08-11 05:31:07 +00008818 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008819 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008820 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008821
Douglas Gregor9da64192010-04-26 22:37:10 +00008822 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8823 E->getLocStart(),
8824 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008825 E->getLocEnd());
8826 }
Mike Stump11289f42009-09-09 15:08:12 +00008827
Eli Friedman456f0182012-01-20 01:26:23 +00008828 // We don't know whether the subexpression is potentially evaluated until
8829 // after we perform semantic analysis. We speculatively assume it is
8830 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008831 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008832 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8833 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008834
John McCalldadc5752010-08-24 06:29:42 +00008835 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008836 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008838
Douglas Gregora16548e2009-08-11 05:31:07 +00008839 if (!getDerived().AlwaysRebuild() &&
8840 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008841 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008842
Douglas Gregor9da64192010-04-26 22:37:10 +00008843 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8844 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008845 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008846 E->getLocEnd());
8847}
8848
8849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008850ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008851TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8852 if (E->isTypeOperand()) {
8853 TypeSourceInfo *TInfo
8854 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8855 if (!TInfo)
8856 return ExprError();
8857
8858 if (!getDerived().AlwaysRebuild() &&
8859 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008860 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008861
Douglas Gregor69735112011-03-06 17:40:41 +00008862 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008863 E->getLocStart(),
8864 TInfo,
8865 E->getLocEnd());
8866 }
8867
Francois Pichet9f4f2072010-09-08 12:20:18 +00008868 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8869
8870 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8871 if (SubExpr.isInvalid())
8872 return ExprError();
8873
8874 if (!getDerived().AlwaysRebuild() &&
8875 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008876 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008877
8878 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8879 E->getLocStart(),
8880 SubExpr.get(),
8881 E->getLocEnd());
8882}
8883
8884template<typename Derived>
8885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008887 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008888}
Mike Stump11289f42009-09-09 15:08:12 +00008889
Douglas Gregora16548e2009-08-11 05:31:07 +00008890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008891ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008892TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008893 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008894 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008895}
Mike Stump11289f42009-09-09 15:08:12 +00008896
Douglas Gregora16548e2009-08-11 05:31:07 +00008897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008899TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008900 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008901
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008902 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8903 // Make sure that we capture 'this'.
8904 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008905 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008906 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008907
Douglas Gregorb15af892010-01-07 23:12:05 +00008908 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008909}
Mike Stump11289f42009-09-09 15:08:12 +00008910
Douglas Gregora16548e2009-08-11 05:31:07 +00008911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008913TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008914 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008915 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008917
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 if (!getDerived().AlwaysRebuild() &&
8919 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008920 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008921
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008922 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8923 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008924}
Mike Stump11289f42009-09-09 15:08:12 +00008925
Douglas Gregora16548e2009-08-11 05:31:07 +00008926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008928TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008929 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008930 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8931 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008932 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008934
Chandler Carruth794da4c2010-02-08 06:42:49 +00008935 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008937 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008938
Douglas Gregor033f6752009-12-23 23:03:06 +00008939 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008940}
Mike Stump11289f42009-09-09 15:08:12 +00008941
Douglas Gregora16548e2009-08-11 05:31:07 +00008942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008943ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008944TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8945 FieldDecl *Field
8946 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8947 E->getField()));
8948 if (!Field)
8949 return ExprError();
8950
8951 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008952 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008953
8954 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8955}
8956
8957template<typename Derived>
8958ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008959TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8960 CXXScalarValueInitExpr *E) {
8961 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8962 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008966 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008967 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008968
Chad Rosier1dcde962012-08-08 18:46:20 +00008969 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008970 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008971 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008972}
Mike Stump11289f42009-09-09 15:08:12 +00008973
Douglas Gregora16548e2009-08-11 05:31:07 +00008974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008976TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008977 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008978 TypeSourceInfo *AllocTypeInfo
8979 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8980 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008982
Douglas Gregora16548e2009-08-11 05:31:07 +00008983 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008984 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008985 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008987
Douglas Gregora16548e2009-08-11 05:31:07 +00008988 // Transform the placement arguments (if any).
8989 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008990 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008991 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008992 E->getNumPlacementArgs(), true,
8993 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008995
Sebastian Redl6047f072012-02-16 12:22:20 +00008996 // Transform the initializer (if any).
8997 Expr *OldInit = E->getInitializer();
8998 ExprResult NewInit;
8999 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009000 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009001 if (NewInit.isInvalid())
9002 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009003
Sebastian Redl6047f072012-02-16 12:22:20 +00009004 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009005 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009006 if (E->getOperatorNew()) {
9007 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009008 getDerived().TransformDecl(E->getLocStart(),
9009 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009010 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009011 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009012 }
9013
Craig Topperc3ec1492014-05-26 06:22:03 +00009014 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009015 if (E->getOperatorDelete()) {
9016 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009017 getDerived().TransformDecl(E->getLocStart(),
9018 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009019 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009020 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009022
Douglas Gregora16548e2009-08-11 05:31:07 +00009023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009024 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009026 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009027 OperatorNew == E->getOperatorNew() &&
9028 OperatorDelete == E->getOperatorDelete() &&
9029 !ArgumentChanged) {
9030 // Mark any declarations we need as referenced.
9031 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009032 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009033 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009034 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009035 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009036
Sebastian Redl6047f072012-02-16 12:22:20 +00009037 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009038 QualType ElementType
9039 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9040 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9041 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9042 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009043 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009044 }
9045 }
9046 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009047
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009048 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009049 }
Mike Stump11289f42009-09-09 15:08:12 +00009050
Douglas Gregor0744ef62010-09-07 21:49:58 +00009051 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009052 if (!ArraySize.get()) {
9053 // If no array size was specified, but the new expression was
9054 // instantiated with an array type (e.g., "new T" where T is
9055 // instantiated with "int[4]"), extract the outer bound from the
9056 // array type as our array size. We do this with constant and
9057 // dependently-sized array types.
9058 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9059 if (!ArrayT) {
9060 // Do nothing
9061 } else if (const ConstantArrayType *ConsArrayT
9062 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009063 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9064 SemaRef.Context.getSizeType(),
9065 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009066 AllocType = ConsArrayT->getElementType();
9067 } else if (const DependentSizedArrayType *DepArrayT
9068 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9069 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009070 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009071 AllocType = DepArrayT->getElementType();
9072 }
9073 }
9074 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009075
Douglas Gregora16548e2009-08-11 05:31:07 +00009076 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9077 E->isGlobalNew(),
9078 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009079 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009080 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009081 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009082 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009083 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009084 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009085 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009086 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009087}
Mike Stump11289f42009-09-09 15:08:12 +00009088
Douglas Gregora16548e2009-08-11 05:31:07 +00009089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009092 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009093 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009095
Douglas Gregord2d9da02010-02-26 00:38:10 +00009096 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009097 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009098 if (E->getOperatorDelete()) {
9099 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009100 getDerived().TransformDecl(E->getLocStart(),
9101 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009102 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009103 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009105
Douglas Gregora16548e2009-08-11 05:31:07 +00009106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009107 Operand.get() == E->getArgument() &&
9108 OperatorDelete == E->getOperatorDelete()) {
9109 // Mark any declarations we need as referenced.
9110 // FIXME: instantiation-specific.
9111 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009112 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009113
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009114 if (!E->getArgument()->isTypeDependent()) {
9115 QualType Destroyed = SemaRef.Context.getBaseElementType(
9116 E->getDestroyedType());
9117 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9118 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009119 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009120 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009121 }
9122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009124 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009125 }
Mike Stump11289f42009-09-09 15:08:12 +00009126
Douglas Gregora16548e2009-08-11 05:31:07 +00009127 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9128 E->isGlobalDelete(),
9129 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009130 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009131}
Mike Stump11289f42009-09-09 15:08:12 +00009132
Douglas Gregora16548e2009-08-11 05:31:07 +00009133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009134ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009135TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009136 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009137 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009138 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009140
John McCallba7bf592010-08-24 05:47:05 +00009141 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009142 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009143 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009144 E->getOperatorLoc(),
9145 E->isArrow()? tok::arrow : tok::period,
9146 ObjectTypePtr,
9147 MayBePseudoDestructor);
9148 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009150
John McCallba7bf592010-08-24 05:47:05 +00009151 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009152 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9153 if (QualifierLoc) {
9154 QualifierLoc
9155 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9156 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009157 return ExprError();
9158 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009159 CXXScopeSpec SS;
9160 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009161
Douglas Gregor678f90d2010-02-25 01:56:36 +00009162 PseudoDestructorTypeStorage Destroyed;
9163 if (E->getDestroyedTypeInfo()) {
9164 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009165 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009166 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009167 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009168 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009169 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009170 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009171 // We aren't likely to be able to resolve the identifier down to a type
9172 // now anyway, so just retain the identifier.
9173 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9174 E->getDestroyedTypeLoc());
9175 } else {
9176 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009177 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009178 *E->getDestroyedTypeIdentifier(),
9179 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009180 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009181 SS, ObjectTypePtr,
9182 false);
9183 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009184 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009185
Douglas Gregor678f90d2010-02-25 01:56:36 +00009186 Destroyed
9187 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9188 E->getDestroyedTypeLoc());
9189 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009190
Craig Topperc3ec1492014-05-26 06:22:03 +00009191 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009192 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009193 CXXScopeSpec EmptySS;
9194 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009195 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009196 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009197 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
John McCallb268a282010-08-23 23:25:46 +00009200 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009201 E->getOperatorLoc(),
9202 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009203 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009204 ScopeTypeInfo,
9205 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009206 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009207 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009208}
Mike Stump11289f42009-09-09 15:08:12 +00009209
Douglas Gregorad8a3362009-09-04 17:36:40 +00009210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009211ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009212TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009213 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009214 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9215 Sema::LookupOrdinaryName);
9216
9217 // Transform all the decls.
9218 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9219 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009220 NamedDecl *InstD = static_cast<NamedDecl*>(
9221 getDerived().TransformDecl(Old->getNameLoc(),
9222 *I));
John McCall84d87672009-12-10 09:41:52 +00009223 if (!InstD) {
9224 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9225 // This can happen because of dependent hiding.
9226 if (isa<UsingShadowDecl>(*I))
9227 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009228 else {
9229 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009230 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009231 }
John McCall84d87672009-12-10 09:41:52 +00009232 }
John McCalle66edc12009-11-24 19:00:30 +00009233
9234 // Expand using declarations.
9235 if (isa<UsingDecl>(InstD)) {
9236 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009237 for (auto *I : UD->shadows())
9238 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009239 continue;
9240 }
9241
9242 R.addDecl(InstD);
9243 }
9244
9245 // Resolve a kind, but don't do any further analysis. If it's
9246 // ambiguous, the callee needs to deal with it.
9247 R.resolveKind();
9248
9249 // Rebuild the nested-name qualifier, if present.
9250 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009251 if (Old->getQualifierLoc()) {
9252 NestedNameSpecifierLoc QualifierLoc
9253 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9254 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009255 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009256
Douglas Gregor0da1d432011-02-28 20:01:57 +00009257 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009258 }
9259
Douglas Gregor9262f472010-04-27 18:19:34 +00009260 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009261 CXXRecordDecl *NamingClass
9262 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9263 Old->getNameLoc(),
9264 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009265 if (!NamingClass) {
9266 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009267 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Douglas Gregorda7be082010-04-27 16:10:10 +00009270 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009271 }
9272
Abramo Bagnara7945c982012-01-27 09:46:47 +00009273 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9274
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009275 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009276 // it's a normal declaration name or member reference.
9277 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9278 NamedDecl *D = R.getAsSingle<NamedDecl>();
9279 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9280 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9281 // give a good diagnostic.
9282 if (D && D->isCXXInstanceMember()) {
9283 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9284 /*TemplateArgs=*/nullptr,
9285 /*Scope=*/nullptr);
9286 }
9287
John McCalle66edc12009-11-24 19:00:30 +00009288 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009289 }
John McCalle66edc12009-11-24 19:00:30 +00009290
9291 // If we have template arguments, rebuild them, then rebuild the
9292 // templateid expression.
9293 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009294 if (Old->hasExplicitTemplateArgs() &&
9295 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009296 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009297 TransArgs)) {
9298 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009299 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009300 }
John McCalle66edc12009-11-24 19:00:30 +00009301
Abramo Bagnara7945c982012-01-27 09:46:47 +00009302 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009303 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009304}
Mike Stump11289f42009-09-09 15:08:12 +00009305
Douglas Gregora16548e2009-08-11 05:31:07 +00009306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009307ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009308TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9309 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009310 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009311 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9312 TypeSourceInfo *From = E->getArg(I);
9313 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009314 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009315 TypeLocBuilder TLB;
9316 TLB.reserve(FromTL.getFullDataSize());
9317 QualType To = getDerived().TransformType(TLB, FromTL);
9318 if (To.isNull())
9319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
Douglas Gregor29c42f22012-02-24 07:38:34 +00009321 if (To == From->getType())
9322 Args.push_back(From);
9323 else {
9324 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9325 ArgChanged = true;
9326 }
9327 continue;
9328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009329
Douglas Gregor29c42f22012-02-24 07:38:34 +00009330 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009331
Douglas Gregor29c42f22012-02-24 07:38:34 +00009332 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009333 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009334 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9336 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009337
Douglas Gregor29c42f22012-02-24 07:38:34 +00009338 // Determine whether the set of unexpanded parameter packs can and should
9339 // be expanded.
9340 bool Expand = true;
9341 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009342 Optional<unsigned> OrigNumExpansions =
9343 ExpansionTL.getTypePtr()->getNumExpansions();
9344 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009345 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9346 PatternTL.getSourceRange(),
9347 Unexpanded,
9348 Expand, RetainExpansion,
9349 NumExpansions))
9350 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009351
Douglas Gregor29c42f22012-02-24 07:38:34 +00009352 if (!Expand) {
9353 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009354 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009355 // expansion.
9356 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009357
Douglas Gregor29c42f22012-02-24 07:38:34 +00009358 TypeLocBuilder TLB;
9359 TLB.reserve(From->getTypeLoc().getFullDataSize());
9360
9361 QualType To = getDerived().TransformType(TLB, PatternTL);
9362 if (To.isNull())
9363 return ExprError();
9364
Chad Rosier1dcde962012-08-08 18:46:20 +00009365 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009366 PatternTL.getSourceRange(),
9367 ExpansionTL.getEllipsisLoc(),
9368 NumExpansions);
9369 if (To.isNull())
9370 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009371
Douglas Gregor29c42f22012-02-24 07:38:34 +00009372 PackExpansionTypeLoc ToExpansionTL
9373 = TLB.push<PackExpansionTypeLoc>(To);
9374 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9375 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9376 continue;
9377 }
9378
9379 // Expand the pack expansion by substituting for each argument in the
9380 // pack(s).
9381 for (unsigned I = 0; I != *NumExpansions; ++I) {
9382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9383 TypeLocBuilder TLB;
9384 TLB.reserve(PatternTL.getFullDataSize());
9385 QualType To = getDerived().TransformType(TLB, PatternTL);
9386 if (To.isNull())
9387 return ExprError();
9388
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009389 if (To->containsUnexpandedParameterPack()) {
9390 To = getDerived().RebuildPackExpansionType(To,
9391 PatternTL.getSourceRange(),
9392 ExpansionTL.getEllipsisLoc(),
9393 NumExpansions);
9394 if (To.isNull())
9395 return ExprError();
9396
9397 PackExpansionTypeLoc ToExpansionTL
9398 = TLB.push<PackExpansionTypeLoc>(To);
9399 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9400 }
9401
Douglas Gregor29c42f22012-02-24 07:38:34 +00009402 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregor29c42f22012-02-24 07:38:34 +00009405 if (!RetainExpansion)
9406 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009407
Douglas Gregor29c42f22012-02-24 07:38:34 +00009408 // If we're supposed to retain a pack expansion, do so by temporarily
9409 // forgetting the partially-substituted parameter pack.
9410 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9411
9412 TypeLocBuilder TLB;
9413 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009414
Douglas Gregor29c42f22012-02-24 07:38:34 +00009415 QualType To = getDerived().TransformType(TLB, PatternTL);
9416 if (To.isNull())
9417 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009418
9419 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009420 PatternTL.getSourceRange(),
9421 ExpansionTL.getEllipsisLoc(),
9422 NumExpansions);
9423 if (To.isNull())
9424 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009425
Douglas Gregor29c42f22012-02-24 07:38:34 +00009426 PackExpansionTypeLoc ToExpansionTL
9427 = TLB.push<PackExpansionTypeLoc>(To);
9428 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9429 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009431
Douglas Gregor29c42f22012-02-24 07:38:34 +00009432 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009433 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009434
9435 return getDerived().RebuildTypeTrait(E->getTrait(),
9436 E->getLocStart(),
9437 Args,
9438 E->getLocEnd());
9439}
9440
9441template<typename Derived>
9442ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009443TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9444 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9445 if (!T)
9446 return ExprError();
9447
9448 if (!getDerived().AlwaysRebuild() &&
9449 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009450 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009451
9452 ExprResult SubExpr;
9453 {
9454 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9455 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9456 if (SubExpr.isInvalid())
9457 return ExprError();
9458
9459 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009460 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009461 }
9462
9463 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9464 E->getLocStart(),
9465 T,
9466 SubExpr.get(),
9467 E->getLocEnd());
9468}
9469
9470template<typename Derived>
9471ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009472TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9473 ExprResult SubExpr;
9474 {
9475 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9476 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9477 if (SubExpr.isInvalid())
9478 return ExprError();
9479
9480 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009481 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009482 }
9483
9484 return getDerived().RebuildExpressionTrait(
9485 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9486}
9487
Reid Kleckner32506ed2014-06-12 23:03:48 +00009488template <typename Derived>
9489ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9490 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9491 TypeSourceInfo **RecoveryTSI) {
9492 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9493 DRE, AddrTaken, RecoveryTSI);
9494
9495 // Propagate both errors and recovered types, which return ExprEmpty.
9496 if (!NewDRE.isUsable())
9497 return NewDRE;
9498
9499 // We got an expr, wrap it up in parens.
9500 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9501 return PE;
9502 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9503 PE->getRParen());
9504}
9505
9506template <typename Derived>
9507ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9508 DependentScopeDeclRefExpr *E) {
9509 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9510 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009511}
9512
9513template<typename Derived>
9514ExprResult
9515TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9516 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009517 bool IsAddressOfOperand,
9518 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009519 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009520 NestedNameSpecifierLoc QualifierLoc
9521 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9522 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009523 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009524 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009525
John McCall31f82722010-11-12 08:19:04 +00009526 // TODO: If this is a conversion-function-id, verify that the
9527 // destination type name (if present) resolves the same way after
9528 // instantiation as it did in the local scope.
9529
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009530 DeclarationNameInfo NameInfo
9531 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9532 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009534
John McCalle66edc12009-11-24 19:00:30 +00009535 if (!E->hasExplicitTemplateArgs()) {
9536 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009537 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009538 // Note: it is sufficient to compare the Name component of NameInfo:
9539 // if name has not changed, DNLoc has not changed either.
9540 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009541 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009542
Reid Kleckner32506ed2014-06-12 23:03:48 +00009543 return getDerived().RebuildDependentScopeDeclRefExpr(
9544 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9545 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009546 }
John McCall6b51f282009-11-23 01:53:49 +00009547
9548 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009549 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9550 E->getNumTemplateArgs(),
9551 TransArgs))
9552 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009553
Reid Kleckner32506ed2014-06-12 23:03:48 +00009554 return getDerived().RebuildDependentScopeDeclRefExpr(
9555 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9556 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009557}
9558
9559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009561TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009562 // CXXConstructExprs other than for list-initialization and
9563 // CXXTemporaryObjectExpr are always implicit, so when we have
9564 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009565 if ((E->getNumArgs() == 1 ||
9566 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009567 (!getDerived().DropCallArgument(E->getArg(0))) &&
9568 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009569 return getDerived().TransformExpr(E->getArg(0));
9570
Douglas Gregora16548e2009-08-11 05:31:07 +00009571 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9572
9573 QualType T = getDerived().TransformType(E->getType());
9574 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009575 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009576
9577 CXXConstructorDecl *Constructor
9578 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009579 getDerived().TransformDecl(E->getLocStart(),
9580 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009581 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009583
Douglas Gregora16548e2009-08-11 05:31:07 +00009584 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009585 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009586 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009587 &ArgumentChanged))
9588 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009589
Douglas Gregora16548e2009-08-11 05:31:07 +00009590 if (!getDerived().AlwaysRebuild() &&
9591 T == E->getType() &&
9592 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009593 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009594 // Mark the constructor as referenced.
9595 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009596 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009597 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009598 }
Mike Stump11289f42009-09-09 15:08:12 +00009599
Douglas Gregordb121ba2009-12-14 16:27:04 +00009600 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9601 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009602 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009603 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009604 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009605 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009606 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009607 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009608 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009609}
Mike Stump11289f42009-09-09 15:08:12 +00009610
Douglas Gregora16548e2009-08-11 05:31:07 +00009611/// \brief Transform a C++ temporary-binding expression.
9612///
Douglas Gregor363b1512009-12-24 18:51:59 +00009613/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9614/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009617TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009618 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009619}
Mike Stump11289f42009-09-09 15:08:12 +00009620
John McCall5d413782010-12-06 08:20:24 +00009621/// \brief Transform a C++ expression that contains cleanups that should
9622/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009623///
John McCall5d413782010-12-06 08:20:24 +00009624/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009625/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009627ExprResult
John McCall5d413782010-12-06 08:20:24 +00009628TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009629 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009630}
Mike Stump11289f42009-09-09 15:08:12 +00009631
Douglas Gregora16548e2009-08-11 05:31:07 +00009632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009633ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009634TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009635 CXXTemporaryObjectExpr *E) {
9636 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9637 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009639
Douglas Gregora16548e2009-08-11 05:31:07 +00009640 CXXConstructorDecl *Constructor
9641 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009642 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009643 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009644 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009646
Douglas Gregora16548e2009-08-11 05:31:07 +00009647 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009648 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009649 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009650 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009651 &ArgumentChanged))
9652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009653
Douglas Gregora16548e2009-08-11 05:31:07 +00009654 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009655 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009657 !ArgumentChanged) {
9658 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009659 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009660 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009662
Richard Smithd59b8322012-12-19 01:39:02 +00009663 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009664 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9665 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009666 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 E->getLocEnd());
9668}
Mike Stump11289f42009-09-09 15:08:12 +00009669
Douglas Gregora16548e2009-08-11 05:31:07 +00009670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009671ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009672TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009673 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009674 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009675 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009676 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9677 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009678 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009679 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009680 CEnd = E->capture_end();
9681 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009682 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009683 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009684 EnterExpressionEvaluationContext EEEC(getSema(),
9685 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009686 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9687 C->getCapturedVar()->getInit(),
9688 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009689
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009690 if (NewExprInitResult.isInvalid())
9691 return ExprError();
9692 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009693
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009694 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009695 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009696 getSema().buildLambdaInitCaptureInitialization(
9697 C->getLocation(), OldVD->getType()->isReferenceType(),
9698 OldVD->getIdentifier(),
9699 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009700 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009701 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9702 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009703 }
9704
Faisal Vali2cba1332013-10-23 06:44:28 +00009705 // Transform the template parameters, and add them to the current
9706 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009707 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009708 E->getTemplateParameterList());
9709
Richard Smith01014ce2014-11-20 23:53:14 +00009710 // Transform the type of the original lambda's call operator.
9711 // The transformation MUST be done in the CurrentInstantiationScope since
9712 // it introduces a mapping of the original to the newly created
9713 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009714 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009715 {
9716 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9717 FunctionProtoTypeLoc OldCallOpFPTL =
9718 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009719
9720 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009721 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009722 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009723 QualType NewCallOpType = TransformFunctionProtoType(
9724 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009725 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9726 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9727 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009728 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009729 if (NewCallOpType.isNull())
9730 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009731 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9732 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009733 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009734
Richard Smithc38498f2015-04-27 21:27:54 +00009735 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9736 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9737 LSI->GLTemplateParameterList = TPL;
9738
Eli Friedmand564afb2012-09-19 01:18:11 +00009739 // Create the local class that will describe the lambda.
9740 CXXRecordDecl *Class
9741 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009742 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009743 /*KnownDependent=*/false,
9744 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009745 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9746
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009747 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009748 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9749 Class, E->getIntroducerRange(), NewCallOpTSI,
9750 E->getCallOperator()->getLocEnd(),
9751 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009752 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009753
Faisal Vali2cba1332013-10-23 06:44:28 +00009754 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009755 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009756
Douglas Gregorb4328232012-02-14 00:00:48 +00009757 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009758 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009759 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009760
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009761 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009762 getSema().buildLambdaScope(LSI, NewCallOperator,
9763 E->getIntroducerRange(),
9764 E->getCaptureDefault(),
9765 E->getCaptureDefaultLoc(),
9766 E->hasExplicitParameters(),
9767 E->hasExplicitResultType(),
9768 E->isMutable());
9769
9770 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009771
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009772 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009773 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009774 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009775 CEnd = E->capture_end();
9776 C != CEnd; ++C) {
9777 // When we hit the first implicit capture, tell Sema that we've finished
9778 // the list of explicit captures.
9779 if (!FinishedExplicitCaptures && C->isImplicit()) {
9780 getSema().finishLambdaExplicitCaptures(LSI);
9781 FinishedExplicitCaptures = true;
9782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009784 // Capturing 'this' is trivial.
9785 if (C->capturesThis()) {
9786 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9787 continue;
9788 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009789 // Captured expression will be recaptured during captured variables
9790 // rebuilding.
9791 if (C->capturesVLAType())
9792 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009793
Richard Smithba71c082013-05-16 06:20:58 +00009794 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009795 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009796 InitCaptureInfoTy InitExprTypePair =
9797 InitCaptureExprsAndTypes[C - E->capture_begin()];
9798 ExprResult Init = InitExprTypePair.first;
9799 QualType InitQualType = InitExprTypePair.second;
9800 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009801 Invalid = true;
9802 continue;
9803 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009804 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009805 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +00009806 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9807 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009808 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009809 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009810 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009811 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009812 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009813 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009814 continue;
9815 }
9816
9817 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9818
Douglas Gregor3e308b12012-02-14 19:27:52 +00009819 // Determine the capture kind for Sema.
9820 Sema::TryCaptureKind Kind
9821 = C->isImplicit()? Sema::TryCapture_Implicit
9822 : C->getCaptureKind() == LCK_ByCopy
9823 ? Sema::TryCapture_ExplicitByVal
9824 : Sema::TryCapture_ExplicitByRef;
9825 SourceLocation EllipsisLoc;
9826 if (C->isPackExpansion()) {
9827 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9828 bool ShouldExpand = false;
9829 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009830 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009831 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9832 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009833 Unexpanded,
9834 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009835 NumExpansions)) {
9836 Invalid = true;
9837 continue;
9838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009839
Douglas Gregor3e308b12012-02-14 19:27:52 +00009840 if (ShouldExpand) {
9841 // The transform has determined that we should perform an expansion;
9842 // transform and capture each of the arguments.
9843 // expansion of the pattern. Do so.
9844 VarDecl *Pack = C->getCapturedVar();
9845 for (unsigned I = 0; I != *NumExpansions; ++I) {
9846 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9847 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009848 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009849 Pack));
9850 if (!CapturedVar) {
9851 Invalid = true;
9852 continue;
9853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009854
Douglas Gregor3e308b12012-02-14 19:27:52 +00009855 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009856 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9857 }
Richard Smith9467be42014-06-06 17:33:35 +00009858
9859 // FIXME: Retain a pack expansion if RetainExpansion is true.
9860
Douglas Gregor3e308b12012-02-14 19:27:52 +00009861 continue;
9862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009863
Douglas Gregor3e308b12012-02-14 19:27:52 +00009864 EllipsisLoc = C->getEllipsisLoc();
9865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009866
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009867 // Transform the captured variable.
9868 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009869 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009870 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009871 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009872 Invalid = true;
9873 continue;
9874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009875
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009876 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009877 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9878 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009879 }
9880 if (!FinishedExplicitCaptures)
9881 getSema().finishLambdaExplicitCaptures(LSI);
9882
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009883 // Enter a new evaluation context to insulate the lambda from any
9884 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009885 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009886
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009887 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009888 StmtResult Body =
9889 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9890
9891 // ActOnLambda* will pop the function scope for us.
9892 FuncScopeCleanup.disable();
9893
Douglas Gregorb4328232012-02-14 00:00:48 +00009894 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009895 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009896 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009897 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009898 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009899 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009900
Richard Smithc38498f2015-04-27 21:27:54 +00009901 // Copy the LSI before ActOnFinishFunctionBody removes it.
9902 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9903 // the call operator.
9904 auto LSICopy = *LSI;
9905 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9906 /*IsInstantiation*/ true);
9907 SavedContext.pop();
9908
9909 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9910 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009911}
9912
9913template<typename Derived>
9914ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009915TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009916 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009917 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9918 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009920
Douglas Gregora16548e2009-08-11 05:31:07 +00009921 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009922 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009923 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009924 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009925 &ArgumentChanged))
9926 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009927
Douglas Gregora16548e2009-08-11 05:31:07 +00009928 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009929 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009930 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009931 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009932
Douglas Gregora16548e2009-08-11 05:31:07 +00009933 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009934 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009935 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009936 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009937 E->getRParenLoc());
9938}
Mike Stump11289f42009-09-09 15:08:12 +00009939
Douglas Gregora16548e2009-08-11 05:31:07 +00009940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009941ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009942TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009943 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009944 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009945 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009946 Expr *OldBase;
9947 QualType BaseType;
9948 QualType ObjectType;
9949 if (!E->isImplicitAccess()) {
9950 OldBase = E->getBase();
9951 Base = getDerived().TransformExpr(OldBase);
9952 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009954
John McCall2d74de92009-12-01 22:10:20 +00009955 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009956 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009957 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009958 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009959 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009960 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009961 ObjectTy,
9962 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009963 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009964 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009965
John McCallba7bf592010-08-24 05:47:05 +00009966 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009967 BaseType = ((Expr*) Base.get())->getType();
9968 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009969 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009970 BaseType = getDerived().TransformType(E->getBaseType());
9971 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9972 }
Mike Stump11289f42009-09-09 15:08:12 +00009973
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009974 // Transform the first part of the nested-name-specifier that qualifies
9975 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009976 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009977 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009978 E->getFirstQualifierFoundInScope(),
9979 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009980
Douglas Gregore16af532011-02-28 18:50:33 +00009981 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009982 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009983 QualifierLoc
9984 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9985 ObjectType,
9986 FirstQualifierInScope);
9987 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009988 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009989 }
Mike Stump11289f42009-09-09 15:08:12 +00009990
Abramo Bagnara7945c982012-01-27 09:46:47 +00009991 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9992
John McCall31f82722010-11-12 08:19:04 +00009993 // TODO: If this is a conversion-function-id, verify that the
9994 // destination type name (if present) resolves the same way after
9995 // instantiation as it did in the local scope.
9996
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009997 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009998 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009999 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010001
John McCall2d74de92009-12-01 22:10:20 +000010002 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010003 // This is a reference to a member without an explicitly-specified
10004 // template argument list. Optimize for this common case.
10005 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010006 Base.get() == OldBase &&
10007 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010008 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010009 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010010 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010011 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010012
John McCallb268a282010-08-23 23:25:46 +000010013 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010014 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010015 E->isArrow(),
10016 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010017 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010018 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010019 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010020 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010021 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010022 }
10023
John McCall6b51f282009-11-23 01:53:49 +000010024 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010025 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10026 E->getNumTemplateArgs(),
10027 TransArgs))
10028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010029
John McCallb268a282010-08-23 23:25:46 +000010030 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010031 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 E->isArrow(),
10033 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010034 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010035 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010036 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010037 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010038 &TransArgs);
10039}
10040
10041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010043TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010044 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010045 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010046 QualType BaseType;
10047 if (!Old->isImplicitAccess()) {
10048 Base = getDerived().TransformExpr(Old->getBase());
10049 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010050 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010051 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010052 Old->isArrow());
10053 if (Base.isInvalid())
10054 return ExprError();
10055 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010056 } else {
10057 BaseType = getDerived().TransformType(Old->getBaseType());
10058 }
John McCall10eae182009-11-30 22:42:35 +000010059
Douglas Gregor0da1d432011-02-28 20:01:57 +000010060 NestedNameSpecifierLoc QualifierLoc;
10061 if (Old->getQualifierLoc()) {
10062 QualifierLoc
10063 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10064 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010065 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010066 }
10067
Abramo Bagnara7945c982012-01-27 09:46:47 +000010068 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10069
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010070 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010071 Sema::LookupOrdinaryName);
10072
10073 // Transform all the decls.
10074 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10075 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010076 NamedDecl *InstD = static_cast<NamedDecl*>(
10077 getDerived().TransformDecl(Old->getMemberLoc(),
10078 *I));
John McCall84d87672009-12-10 09:41:52 +000010079 if (!InstD) {
10080 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10081 // This can happen because of dependent hiding.
10082 if (isa<UsingShadowDecl>(*I))
10083 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010084 else {
10085 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010086 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010087 }
John McCall84d87672009-12-10 09:41:52 +000010088 }
John McCall10eae182009-11-30 22:42:35 +000010089
10090 // Expand using declarations.
10091 if (isa<UsingDecl>(InstD)) {
10092 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010093 for (auto *I : UD->shadows())
10094 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010095 continue;
10096 }
10097
10098 R.addDecl(InstD);
10099 }
10100
10101 R.resolveKind();
10102
Douglas Gregor9262f472010-04-27 18:19:34 +000010103 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010104 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010105 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010106 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010107 Old->getMemberLoc(),
10108 Old->getNamingClass()));
10109 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010110 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010111
Douglas Gregorda7be082010-04-27 16:10:10 +000010112 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010113 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010114
John McCall10eae182009-11-30 22:42:35 +000010115 TemplateArgumentListInfo TransArgs;
10116 if (Old->hasExplicitTemplateArgs()) {
10117 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10118 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010119 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10120 Old->getNumTemplateArgs(),
10121 TransArgs))
10122 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010123 }
John McCall38836f02010-01-15 08:34:02 +000010124
10125 // FIXME: to do this check properly, we will need to preserve the
10126 // first-qualifier-in-scope here, just in case we had a dependent
10127 // base (and therefore couldn't do the check) and a
10128 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010129 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010130
John McCallb268a282010-08-23 23:25:46 +000010131 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010132 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010133 Old->getOperatorLoc(),
10134 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010135 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010136 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010137 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010138 R,
10139 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010140 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010141}
10142
10143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010144ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010145TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010147 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10148 if (SubExpr.isInvalid())
10149 return ExprError();
10150
10151 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010152 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010153
10154 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10155}
10156
10157template<typename Derived>
10158ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010159TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010160 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10161 if (Pattern.isInvalid())
10162 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010163
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010164 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010165 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010166
Douglas Gregorb8840002011-01-14 21:20:45 +000010167 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10168 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010169}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010170
10171template<typename Derived>
10172ExprResult
10173TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10174 // If E is not value-dependent, then nothing will change when we transform it.
10175 // Note: This is an instantiation-centric view.
10176 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010177 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010178
Richard Smithd784e682015-09-23 21:41:42 +000010179 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010180
Richard Smithd784e682015-09-23 21:41:42 +000010181 ArrayRef<TemplateArgument> PackArgs;
10182 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010183
Richard Smithd784e682015-09-23 21:41:42 +000010184 // Find the argument list to transform.
10185 if (E->isPartiallySubstituted()) {
10186 PackArgs = E->getPartialArguments();
10187 } else if (E->isValueDependent()) {
10188 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10189 bool ShouldExpand = false;
10190 bool RetainExpansion = false;
10191 Optional<unsigned> NumExpansions;
10192 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10193 Unexpanded,
10194 ShouldExpand, RetainExpansion,
10195 NumExpansions))
10196 return ExprError();
10197
10198 // If we need to expand the pack, build a template argument from it and
10199 // expand that.
10200 if (ShouldExpand) {
10201 auto *Pack = E->getPack();
10202 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10203 ArgStorage = getSema().Context.getPackExpansionType(
10204 getSema().Context.getTypeDeclType(TTPD), None);
10205 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10206 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10207 } else {
10208 auto *VD = cast<ValueDecl>(Pack);
10209 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10210 VK_RValue, E->getPackLoc());
10211 if (DRE.isInvalid())
10212 return ExprError();
10213 ArgStorage = new (getSema().Context) PackExpansionExpr(
10214 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10215 }
10216 PackArgs = ArgStorage;
10217 }
10218 }
10219
10220 // If we're not expanding the pack, just transform the decl.
10221 if (!PackArgs.size()) {
10222 auto *Pack = cast_or_null<NamedDecl>(
10223 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010224 if (!Pack)
10225 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010226 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10227 E->getPackLoc(),
10228 E->getRParenLoc(), None, None);
10229 }
10230
10231 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10232 E->getPackLoc());
10233 {
10234 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10235 typedef TemplateArgumentLocInventIterator<
10236 Derived, const TemplateArgument*> PackLocIterator;
10237 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10238 PackLocIterator(*this, PackArgs.end()),
10239 TransformedPackArgs, /*Uneval*/true))
10240 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010241 }
10242
Richard Smithd784e682015-09-23 21:41:42 +000010243 SmallVector<TemplateArgument, 8> Args;
10244 bool PartialSubstitution = false;
10245 for (auto &Loc : TransformedPackArgs.arguments()) {
10246 Args.push_back(Loc.getArgument());
10247 if (Loc.getArgument().isPackExpansion())
10248 PartialSubstitution = true;
10249 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010250
Richard Smithd784e682015-09-23 21:41:42 +000010251 if (PartialSubstitution)
10252 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10253 E->getPackLoc(),
10254 E->getRParenLoc(), None, Args);
10255
10256 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010257 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010258 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010259}
10260
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010261template<typename Derived>
10262ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010263TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10264 SubstNonTypeTemplateParmPackExpr *E) {
10265 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010266 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010267}
10268
10269template<typename Derived>
10270ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010271TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10272 SubstNonTypeTemplateParmExpr *E) {
10273 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010274 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010275}
10276
10277template<typename Derived>
10278ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010279TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10280 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010281 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010282}
10283
10284template<typename Derived>
10285ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010286TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10287 MaterializeTemporaryExpr *E) {
10288 return getDerived().TransformExpr(E->GetTemporaryExpr());
10289}
Chad Rosier1dcde962012-08-08 18:46:20 +000010290
Douglas Gregorfe314812011-06-21 17:03:29 +000010291template<typename Derived>
10292ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010293TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10294 Expr *Pattern = E->getPattern();
10295
10296 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10297 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10298 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10299
10300 // Determine whether the set of unexpanded parameter packs can and should
10301 // be expanded.
10302 bool Expand = true;
10303 bool RetainExpansion = false;
10304 Optional<unsigned> NumExpansions;
10305 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10306 Pattern->getSourceRange(),
10307 Unexpanded,
10308 Expand, RetainExpansion,
10309 NumExpansions))
10310 return true;
10311
10312 if (!Expand) {
10313 // Do not expand any packs here, just transform and rebuild a fold
10314 // expression.
10315 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10316
10317 ExprResult LHS =
10318 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10319 if (LHS.isInvalid())
10320 return true;
10321
10322 ExprResult RHS =
10323 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10324 if (RHS.isInvalid())
10325 return true;
10326
10327 if (!getDerived().AlwaysRebuild() &&
10328 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10329 return E;
10330
10331 return getDerived().RebuildCXXFoldExpr(
10332 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10333 RHS.get(), E->getLocEnd());
10334 }
10335
10336 // The transform has determined that we should perform an elementwise
10337 // expansion of the pattern. Do so.
10338 ExprResult Result = getDerived().TransformExpr(E->getInit());
10339 if (Result.isInvalid())
10340 return true;
10341 bool LeftFold = E->isLeftFold();
10342
10343 // If we're retaining an expansion for a right fold, it is the innermost
10344 // component and takes the init (if any).
10345 if (!LeftFold && RetainExpansion) {
10346 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10347
10348 ExprResult Out = getDerived().TransformExpr(Pattern);
10349 if (Out.isInvalid())
10350 return true;
10351
10352 Result = getDerived().RebuildCXXFoldExpr(
10353 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10354 Result.get(), E->getLocEnd());
10355 if (Result.isInvalid())
10356 return true;
10357 }
10358
10359 for (unsigned I = 0; I != *NumExpansions; ++I) {
10360 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10361 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10362 ExprResult Out = getDerived().TransformExpr(Pattern);
10363 if (Out.isInvalid())
10364 return true;
10365
10366 if (Out.get()->containsUnexpandedParameterPack()) {
10367 // We still have a pack; retain a pack expansion for this slice.
10368 Result = getDerived().RebuildCXXFoldExpr(
10369 E->getLocStart(),
10370 LeftFold ? Result.get() : Out.get(),
10371 E->getOperator(), E->getEllipsisLoc(),
10372 LeftFold ? Out.get() : Result.get(),
10373 E->getLocEnd());
10374 } else if (Result.isUsable()) {
10375 // We've got down to a single element; build a binary operator.
10376 Result = getDerived().RebuildBinaryOperator(
10377 E->getEllipsisLoc(), E->getOperator(),
10378 LeftFold ? Result.get() : Out.get(),
10379 LeftFold ? Out.get() : Result.get());
10380 } else
10381 Result = Out;
10382
10383 if (Result.isInvalid())
10384 return true;
10385 }
10386
10387 // If we're retaining an expansion for a left fold, it is the outermost
10388 // component and takes the complete expansion so far as its init (if any).
10389 if (LeftFold && RetainExpansion) {
10390 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10391
10392 ExprResult Out = getDerived().TransformExpr(Pattern);
10393 if (Out.isInvalid())
10394 return true;
10395
10396 Result = getDerived().RebuildCXXFoldExpr(
10397 E->getLocStart(), Result.get(),
10398 E->getOperator(), E->getEllipsisLoc(),
10399 Out.get(), E->getLocEnd());
10400 if (Result.isInvalid())
10401 return true;
10402 }
10403
10404 // If we had no init and an empty pack, and we're not retaining an expansion,
10405 // then produce a fallback value or error.
10406 if (Result.isUnset())
10407 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10408 E->getOperator());
10409
10410 return Result;
10411}
10412
10413template<typename Derived>
10414ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010415TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10416 CXXStdInitializerListExpr *E) {
10417 return getDerived().TransformExpr(E->getSubExpr());
10418}
10419
10420template<typename Derived>
10421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010422TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010423 return SemaRef.MaybeBindToTemporary(E);
10424}
10425
10426template<typename Derived>
10427ExprResult
10428TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010429 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010430}
10431
10432template<typename Derived>
10433ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010434TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10435 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10436 if (SubExpr.isInvalid())
10437 return ExprError();
10438
10439 if (!getDerived().AlwaysRebuild() &&
10440 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010441 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010442
10443 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010444}
10445
10446template<typename Derived>
10447ExprResult
10448TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10449 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010450 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010451 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010452 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010453 /*IsCall=*/false, Elements, &ArgChanged))
10454 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010455
Ted Kremeneke65b0862012-03-06 20:05:56 +000010456 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10457 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010458
Ted Kremeneke65b0862012-03-06 20:05:56 +000010459 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10460 Elements.data(),
10461 Elements.size());
10462}
10463
10464template<typename Derived>
10465ExprResult
10466TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010467 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010468 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010469 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010470 bool ArgChanged = false;
10471 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10472 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010473
Ted Kremeneke65b0862012-03-06 20:05:56 +000010474 if (OrigElement.isPackExpansion()) {
10475 // This key/value element is a pack expansion.
10476 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10477 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10478 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10479 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10480
10481 // Determine whether the set of unexpanded parameter packs can
10482 // and should be expanded.
10483 bool Expand = true;
10484 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010485 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10486 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010487 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10488 OrigElement.Value->getLocEnd());
10489 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10490 PatternRange,
10491 Unexpanded,
10492 Expand, RetainExpansion,
10493 NumExpansions))
10494 return ExprError();
10495
10496 if (!Expand) {
10497 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010498 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010499 // expansion.
10500 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10501 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10502 if (Key.isInvalid())
10503 return ExprError();
10504
10505 if (Key.get() != OrigElement.Key)
10506 ArgChanged = true;
10507
10508 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10509 if (Value.isInvalid())
10510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010511
Ted Kremeneke65b0862012-03-06 20:05:56 +000010512 if (Value.get() != OrigElement.Value)
10513 ArgChanged = true;
10514
Chad Rosier1dcde962012-08-08 18:46:20 +000010515 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010516 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10517 };
10518 Elements.push_back(Expansion);
10519 continue;
10520 }
10521
10522 // Record right away that the argument was changed. This needs
10523 // to happen even if the array expands to nothing.
10524 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010525
Ted Kremeneke65b0862012-03-06 20:05:56 +000010526 // The transform has determined that we should perform an elementwise
10527 // expansion of the pattern. Do so.
10528 for (unsigned I = 0; I != *NumExpansions; ++I) {
10529 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10530 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10531 if (Key.isInvalid())
10532 return ExprError();
10533
10534 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10535 if (Value.isInvalid())
10536 return ExprError();
10537
Chad Rosier1dcde962012-08-08 18:46:20 +000010538 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010539 Key.get(), Value.get(), SourceLocation(), NumExpansions
10540 };
10541
10542 // If any unexpanded parameter packs remain, we still have a
10543 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010544 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010545 if (Key.get()->containsUnexpandedParameterPack() ||
10546 Value.get()->containsUnexpandedParameterPack())
10547 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010548
Ted Kremeneke65b0862012-03-06 20:05:56 +000010549 Elements.push_back(Element);
10550 }
10551
Richard Smith9467be42014-06-06 17:33:35 +000010552 // FIXME: Retain a pack expansion if RetainExpansion is true.
10553
Ted Kremeneke65b0862012-03-06 20:05:56 +000010554 // We've finished with this pack expansion.
10555 continue;
10556 }
10557
10558 // Transform and check key.
10559 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10560 if (Key.isInvalid())
10561 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010562
Ted Kremeneke65b0862012-03-06 20:05:56 +000010563 if (Key.get() != OrigElement.Key)
10564 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010565
Ted Kremeneke65b0862012-03-06 20:05:56 +000010566 // Transform and check value.
10567 ExprResult Value
10568 = getDerived().TransformExpr(OrigElement.Value);
10569 if (Value.isInvalid())
10570 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010571
Ted Kremeneke65b0862012-03-06 20:05:56 +000010572 if (Value.get() != OrigElement.Value)
10573 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010574
10575 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010576 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010577 };
10578 Elements.push_back(Element);
10579 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010580
Ted Kremeneke65b0862012-03-06 20:05:56 +000010581 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10582 return SemaRef.MaybeBindToTemporary(E);
10583
10584 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10585 Elements.data(),
10586 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010587}
10588
Mike Stump11289f42009-09-09 15:08:12 +000010589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010591TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010592 TypeSourceInfo *EncodedTypeInfo
10593 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10594 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010596
Douglas Gregora16548e2009-08-11 05:31:07 +000010597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010598 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010599 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010600
10601 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010602 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010603 E->getRParenLoc());
10604}
Mike Stump11289f42009-09-09 15:08:12 +000010605
Douglas Gregora16548e2009-08-11 05:31:07 +000010606template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010607ExprResult TreeTransform<Derived>::
10608TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010609 // This is a kind of implicit conversion, and it needs to get dropped
10610 // and recomputed for the same general reasons that ImplicitCastExprs
10611 // do, as well a more specific one: this expression is only valid when
10612 // it appears *immediately* as an argument expression.
10613 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010614}
10615
10616template<typename Derived>
10617ExprResult TreeTransform<Derived>::
10618TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010619 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010620 = getDerived().TransformType(E->getTypeInfoAsWritten());
10621 if (!TSInfo)
10622 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
John McCall31168b02011-06-15 23:02:42 +000010624 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010625 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010626 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010627
John McCall31168b02011-06-15 23:02:42 +000010628 if (!getDerived().AlwaysRebuild() &&
10629 TSInfo == E->getTypeInfoAsWritten() &&
10630 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010631 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010632
John McCall31168b02011-06-15 23:02:42 +000010633 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010634 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010635 Result.get());
10636}
10637
10638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010640TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010641 // Transform arguments.
10642 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010643 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010644 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010645 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010646 &ArgChanged))
10647 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010648
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010649 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10650 // Class message: transform the receiver type.
10651 TypeSourceInfo *ReceiverTypeInfo
10652 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10653 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010654 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010655
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010656 // If nothing changed, just retain the existing message send.
10657 if (!getDerived().AlwaysRebuild() &&
10658 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010659 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010660
10661 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010662 SmallVector<SourceLocation, 16> SelLocs;
10663 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010664 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10665 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010666 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010667 E->getMethodDecl(),
10668 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010669 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010670 E->getRightLoc());
10671 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010672 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10673 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10674 // Build a new class message send to 'super'.
10675 SmallVector<SourceLocation, 16> SelLocs;
10676 E->getSelectorLocs(SelLocs);
10677 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10678 E->getSelector(),
10679 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010680 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010681 E->getMethodDecl(),
10682 E->getLeftLoc(),
10683 Args,
10684 E->getRightLoc());
10685 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010686
10687 // Instance message: transform the receiver
10688 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10689 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010690 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010691 = getDerived().TransformExpr(E->getInstanceReceiver());
10692 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010693 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010694
10695 // If nothing changed, just retain the existing message send.
10696 if (!getDerived().AlwaysRebuild() &&
10697 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010698 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010699
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010700 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010701 SmallVector<SourceLocation, 16> SelLocs;
10702 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010703 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010704 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010705 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010706 E->getMethodDecl(),
10707 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010708 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010709 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010710}
10711
Mike Stump11289f42009-09-09 15:08:12 +000010712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010714TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010715 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010716}
10717
Mike Stump11289f42009-09-09 15:08:12 +000010718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010720TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010721 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010722}
10723
Mike Stump11289f42009-09-09 15:08:12 +000010724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010726TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010727 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010728 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010729 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010730 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010731
10732 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010733
Douglas Gregord51d90d2010-04-26 20:11:03 +000010734 // If nothing changed, just retain the existing expression.
10735 if (!getDerived().AlwaysRebuild() &&
10736 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010737 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010738
John McCallb268a282010-08-23 23:25:46 +000010739 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010740 E->getLocation(),
10741 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010742}
10743
Mike Stump11289f42009-09-09 15:08:12 +000010744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010746TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010747 // 'super' and types never change. Property never changes. Just
10748 // retain the existing expression.
10749 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010750 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010751
Douglas Gregor9faee212010-04-26 20:47:02 +000010752 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010753 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010754 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010755 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010756
Douglas Gregor9faee212010-04-26 20:47:02 +000010757 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010758
Douglas Gregor9faee212010-04-26 20:47:02 +000010759 // If nothing changed, just retain the existing expression.
10760 if (!getDerived().AlwaysRebuild() &&
10761 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010762 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010763
John McCallb7bd14f2010-12-02 01:19:52 +000010764 if (E->isExplicitProperty())
10765 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10766 E->getExplicitProperty(),
10767 E->getLocation());
10768
10769 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010770 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010771 E->getImplicitPropertyGetter(),
10772 E->getImplicitPropertySetter(),
10773 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010774}
10775
Mike Stump11289f42009-09-09 15:08:12 +000010776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010777ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010778TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10779 // Transform the base expression.
10780 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10781 if (Base.isInvalid())
10782 return ExprError();
10783
10784 // Transform the key expression.
10785 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10786 if (Key.isInvalid())
10787 return ExprError();
10788
10789 // If nothing changed, just retain the existing expression.
10790 if (!getDerived().AlwaysRebuild() &&
10791 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010792 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010793
Chad Rosier1dcde962012-08-08 18:46:20 +000010794 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010795 Base.get(), Key.get(),
10796 E->getAtIndexMethodDecl(),
10797 E->setAtIndexMethodDecl());
10798}
10799
10800template<typename Derived>
10801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010802TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010803 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010804 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010805 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010806 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010807
Douglas Gregord51d90d2010-04-26 20:11:03 +000010808 // If nothing changed, just retain the existing expression.
10809 if (!getDerived().AlwaysRebuild() &&
10810 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010811 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010812
John McCallb268a282010-08-23 23:25:46 +000010813 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010814 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010815 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010816}
10817
Mike Stump11289f42009-09-09 15:08:12 +000010818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010819ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010820TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010821 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010822 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010823 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010824 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010825 SubExprs, &ArgumentChanged))
10826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010827
Douglas Gregora16548e2009-08-11 05:31:07 +000010828 if (!getDerived().AlwaysRebuild() &&
10829 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010830 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010831
Douglas Gregora16548e2009-08-11 05:31:07 +000010832 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010833 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010834 E->getRParenLoc());
10835}
10836
Mike Stump11289f42009-09-09 15:08:12 +000010837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010838ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010839TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10840 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10841 if (SrcExpr.isInvalid())
10842 return ExprError();
10843
10844 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10845 if (!Type)
10846 return ExprError();
10847
10848 if (!getDerived().AlwaysRebuild() &&
10849 Type == E->getTypeSourceInfo() &&
10850 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010851 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010852
10853 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10854 SrcExpr.get(), Type,
10855 E->getRParenLoc());
10856}
10857
10858template<typename Derived>
10859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010860TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010861 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010862
Craig Topperc3ec1492014-05-26 06:22:03 +000010863 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010864 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10865
10866 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010867 blockScope->TheDecl->setBlockMissingReturnType(
10868 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010869
Chris Lattner01cf8db2011-07-20 06:58:45 +000010870 SmallVector<ParmVarDecl*, 4> params;
10871 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010872
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010873 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010874 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10875 oldBlock->param_begin(),
10876 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010877 nullptr, paramTypes, &params)) {
10878 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010879 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010880 }
John McCall490112f2011-02-04 18:33:18 +000010881
Jordan Rosea0a86be2013-03-08 22:25:36 +000010882 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010883 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010884 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010885
Jordan Rose5c382722013-03-08 21:51:21 +000010886 QualType functionType =
10887 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010888 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010889 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010890
10891 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010892 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010893 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010894
10895 if (!oldBlock->blockMissingReturnType()) {
10896 blockScope->HasImplicitReturnType = false;
10897 blockScope->ReturnType = exprResultType;
10898 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010899
John McCall3882ace2011-01-05 12:14:39 +000010900 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010901 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010902 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010903 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010904 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010905 }
John McCall3882ace2011-01-05 12:14:39 +000010906
John McCall490112f2011-02-04 18:33:18 +000010907#ifndef NDEBUG
10908 // In builds with assertions, make sure that we captured everything we
10909 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010910 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010911 for (const auto &I : oldBlock->captures()) {
10912 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010913
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010914 // Ignore parameter packs.
10915 if (isa<ParmVarDecl>(oldCapture) &&
10916 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10917 continue;
John McCall490112f2011-02-04 18:33:18 +000010918
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010919 VarDecl *newCapture =
10920 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10921 oldCapture));
10922 assert(blockScope->CaptureMap.count(newCapture));
10923 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010924 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010925 }
10926#endif
10927
10928 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010929 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010930}
10931
Mike Stump11289f42009-09-09 15:08:12 +000010932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010933ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010934TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010935 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010936}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010937
10938template<typename Derived>
10939ExprResult
10940TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010941 QualType RetTy = getDerived().TransformType(E->getType());
10942 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010943 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010944 SubExprs.reserve(E->getNumSubExprs());
10945 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10946 SubExprs, &ArgumentChanged))
10947 return ExprError();
10948
10949 if (!getDerived().AlwaysRebuild() &&
10950 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010951 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010952
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010953 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010954 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010955}
Chad Rosier1dcde962012-08-08 18:46:20 +000010956
Douglas Gregora16548e2009-08-11 05:31:07 +000010957//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010958// Type reconstruction
10959//===----------------------------------------------------------------------===//
10960
Mike Stump11289f42009-09-09 15:08:12 +000010961template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010962QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10963 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010964 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010965 getDerived().getBaseEntity());
10966}
10967
Mike Stump11289f42009-09-09 15:08:12 +000010968template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010969QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10970 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010971 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010972 getDerived().getBaseEntity());
10973}
10974
Mike Stump11289f42009-09-09 15:08:12 +000010975template<typename Derived>
10976QualType
John McCall70dd5f62009-10-30 00:06:24 +000010977TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10978 bool WrittenAsLValue,
10979 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010980 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010981 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010982}
10983
10984template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010985QualType
John McCall70dd5f62009-10-30 00:06:24 +000010986TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10987 QualType ClassType,
10988 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010989 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10990 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010991}
10992
10993template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010994QualType TreeTransform<Derived>::RebuildObjCObjectType(
10995 QualType BaseType,
10996 SourceLocation Loc,
10997 SourceLocation TypeArgsLAngleLoc,
10998 ArrayRef<TypeSourceInfo *> TypeArgs,
10999 SourceLocation TypeArgsRAngleLoc,
11000 SourceLocation ProtocolLAngleLoc,
11001 ArrayRef<ObjCProtocolDecl *> Protocols,
11002 ArrayRef<SourceLocation> ProtocolLocs,
11003 SourceLocation ProtocolRAngleLoc) {
11004 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11005 TypeArgs, TypeArgsRAngleLoc,
11006 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11007 ProtocolRAngleLoc,
11008 /*FailOnError=*/true);
11009}
11010
11011template<typename Derived>
11012QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11013 QualType PointeeType,
11014 SourceLocation Star) {
11015 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11016}
11017
11018template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011019QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011020TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11021 ArrayType::ArraySizeModifier SizeMod,
11022 const llvm::APInt *Size,
11023 Expr *SizeExpr,
11024 unsigned IndexTypeQuals,
11025 SourceRange BracketsRange) {
11026 if (SizeExpr || !Size)
11027 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11028 IndexTypeQuals, BracketsRange,
11029 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011030
11031 QualType Types[] = {
11032 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11033 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11034 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011035 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011036 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011037 QualType SizeType;
11038 for (unsigned I = 0; I != NumTypes; ++I)
11039 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11040 SizeType = Types[I];
11041 break;
11042 }
Mike Stump11289f42009-09-09 15:08:12 +000011043
Eli Friedman9562f392012-01-25 23:20:27 +000011044 // Note that we can return a VariableArrayType here in the case where
11045 // the element type was a dependent VariableArrayType.
11046 IntegerLiteral *ArraySize
11047 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11048 /*FIXME*/BracketsRange.getBegin());
11049 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011050 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011051 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011052}
Mike Stump11289f42009-09-09 15:08:12 +000011053
Douglas Gregord6ff3322009-08-04 16:50:30 +000011054template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011055QualType
11056TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011057 ArrayType::ArraySizeModifier SizeMod,
11058 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011059 unsigned IndexTypeQuals,
11060 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011061 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011062 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011063}
11064
11065template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011066QualType
Mike Stump11289f42009-09-09 15:08:12 +000011067TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011068 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011069 unsigned IndexTypeQuals,
11070 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011071 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011072 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011073}
Mike Stump11289f42009-09-09 15:08:12 +000011074
Douglas Gregord6ff3322009-08-04 16:50:30 +000011075template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011076QualType
11077TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011078 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011079 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011080 unsigned IndexTypeQuals,
11081 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011082 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011083 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011084 IndexTypeQuals, BracketsRange);
11085}
11086
11087template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011088QualType
11089TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011090 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011091 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011092 unsigned IndexTypeQuals,
11093 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011094 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011095 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011096 IndexTypeQuals, BracketsRange);
11097}
11098
11099template<typename Derived>
11100QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011101 unsigned NumElements,
11102 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011103 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011104 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011105}
Mike Stump11289f42009-09-09 15:08:12 +000011106
Douglas Gregord6ff3322009-08-04 16:50:30 +000011107template<typename Derived>
11108QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11109 unsigned NumElements,
11110 SourceLocation AttributeLoc) {
11111 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11112 NumElements, true);
11113 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011114 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11115 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011116 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011117}
Mike Stump11289f42009-09-09 15:08:12 +000011118
Douglas Gregord6ff3322009-08-04 16:50:30 +000011119template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011120QualType
11121TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011122 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011123 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011124 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011125}
Mike Stump11289f42009-09-09 15:08:12 +000011126
Douglas Gregord6ff3322009-08-04 16:50:30 +000011127template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011128QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11129 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011130 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011131 const FunctionProtoType::ExtProtoInfo &EPI) {
11132 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011133 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011134 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011135 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011136}
Mike Stump11289f42009-09-09 15:08:12 +000011137
Douglas Gregord6ff3322009-08-04 16:50:30 +000011138template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011139QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11140 return SemaRef.Context.getFunctionNoProtoType(T);
11141}
11142
11143template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011144QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11145 assert(D && "no decl found");
11146 if (D->isInvalidDecl()) return QualType();
11147
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011148 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011149 TypeDecl *Ty;
11150 if (isa<UsingDecl>(D)) {
11151 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011152 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011153 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11154
11155 // A valid resolved using typename decl points to exactly one type decl.
11156 assert(++Using->shadow_begin() == Using->shadow_end());
11157 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011158
John McCallb96ec562009-12-04 22:46:56 +000011159 } else {
11160 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11161 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11162 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11163 }
11164
11165 return SemaRef.Context.getTypeDeclType(Ty);
11166}
11167
11168template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011169QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11170 SourceLocation Loc) {
11171 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011172}
11173
11174template<typename Derived>
11175QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11176 return SemaRef.Context.getTypeOfType(Underlying);
11177}
11178
11179template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011180QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11181 SourceLocation Loc) {
11182 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011183}
11184
11185template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011186QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11187 UnaryTransformType::UTTKind UKind,
11188 SourceLocation Loc) {
11189 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11190}
11191
11192template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011193QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011194 TemplateName Template,
11195 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011196 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011197 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011198}
Mike Stump11289f42009-09-09 15:08:12 +000011199
Douglas Gregor1135c352009-08-06 05:28:30 +000011200template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011201QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11202 SourceLocation KWLoc) {
11203 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11204}
11205
11206template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011207TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011208TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011209 bool TemplateKW,
11210 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011211 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011212 Template);
11213}
11214
11215template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011216TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011217TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11218 const IdentifierInfo &Name,
11219 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011220 QualType ObjectType,
11221 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011222 UnqualifiedId TemplateName;
11223 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011224 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011225 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011226 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011227 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011228 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011229 /*EnteringContext=*/false,
11230 Template);
John McCall31f82722010-11-12 08:19:04 +000011231 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011232}
Mike Stump11289f42009-09-09 15:08:12 +000011233
Douglas Gregora16548e2009-08-11 05:31:07 +000011234template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011235TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011236TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011237 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011238 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011239 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011240 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011241 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011242 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011243 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011244 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011245 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011246 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011247 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011248 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011249 /*EnteringContext=*/false,
11250 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011251 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011252}
Chad Rosier1dcde962012-08-08 18:46:20 +000011253
Douglas Gregor71395fa2009-11-04 00:56:37 +000011254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011255ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011256TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11257 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011258 Expr *OrigCallee,
11259 Expr *First,
11260 Expr *Second) {
11261 Expr *Callee = OrigCallee->IgnoreParenCasts();
11262 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011263
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011264 if (First->getObjectKind() == OK_ObjCProperty) {
11265 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11266 if (BinaryOperator::isAssignmentOp(Opc))
11267 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11268 First, Second);
11269 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11270 if (Result.isInvalid())
11271 return ExprError();
11272 First = Result.get();
11273 }
11274
11275 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11276 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11277 if (Result.isInvalid())
11278 return ExprError();
11279 Second = Result.get();
11280 }
11281
Douglas Gregora16548e2009-08-11 05:31:07 +000011282 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011283 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011284 if (!First->getType()->isOverloadableType() &&
11285 !Second->getType()->isOverloadableType())
11286 return getSema().CreateBuiltinArraySubscriptExpr(First,
11287 Callee->getLocStart(),
11288 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011289 } else if (Op == OO_Arrow) {
11290 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011291 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11292 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011293 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011294 // The argument is not of overloadable type, so try to create a
11295 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011296 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011297 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011298
John McCallb268a282010-08-23 23:25:46 +000011299 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011300 }
11301 } else {
John McCallb268a282010-08-23 23:25:46 +000011302 if (!First->getType()->isOverloadableType() &&
11303 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011304 // Neither of the arguments is an overloadable type, so try to
11305 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011306 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011307 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011308 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011309 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011311
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011312 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011313 }
11314 }
Mike Stump11289f42009-09-09 15:08:12 +000011315
11316 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011317 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011318 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011319
John McCallb268a282010-08-23 23:25:46 +000011320 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011321 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011322 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011323 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011324 // If we've resolved this to a particular non-member function, just call
11325 // that function. If we resolved it to a member function,
11326 // CreateOverloaded* will find that function for us.
11327 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11328 if (!isa<CXXMethodDecl>(ND))
11329 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011330 }
Mike Stump11289f42009-09-09 15:08:12 +000011331
Douglas Gregora16548e2009-08-11 05:31:07 +000011332 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011333 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011334 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011335
Douglas Gregora16548e2009-08-11 05:31:07 +000011336 // Create the overloaded operator invocation for unary operators.
11337 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011338 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011339 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011340 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011341 }
Mike Stump11289f42009-09-09 15:08:12 +000011342
Douglas Gregore9d62932011-07-15 16:25:15 +000011343 if (Op == OO_Subscript) {
11344 SourceLocation LBrace;
11345 SourceLocation RBrace;
11346
11347 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011348 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011349 LBrace = SourceLocation::getFromRawEncoding(
11350 NameLoc.CXXOperatorName.BeginOpNameLoc);
11351 RBrace = SourceLocation::getFromRawEncoding(
11352 NameLoc.CXXOperatorName.EndOpNameLoc);
11353 } else {
11354 LBrace = Callee->getLocStart();
11355 RBrace = OpLoc;
11356 }
11357
11358 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11359 First, Second);
11360 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011361
Douglas Gregora16548e2009-08-11 05:31:07 +000011362 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011363 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011364 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011365 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11366 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011368
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011369 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011370}
Mike Stump11289f42009-09-09 15:08:12 +000011371
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011372template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011373ExprResult
John McCallb268a282010-08-23 23:25:46 +000011374TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011375 SourceLocation OperatorLoc,
11376 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011377 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011378 TypeSourceInfo *ScopeType,
11379 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011380 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011381 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011382 QualType BaseType = Base->getType();
11383 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011384 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011385 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011386 !BaseType->getAs<PointerType>()->getPointeeType()
11387 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011388 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011389 return SemaRef.BuildPseudoDestructorExpr(
11390 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11391 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011392 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011393
Douglas Gregor678f90d2010-02-25 01:56:36 +000011394 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011395 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11396 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11397 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11398 NameInfo.setNamedTypeInfo(DestroyedType);
11399
Richard Smith8e4a3862012-05-15 06:15:11 +000011400 // The scope type is now known to be a valid nested name specifier
11401 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011402 if (ScopeType) {
11403 if (!ScopeType->getType()->getAs<TagType>()) {
11404 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11405 diag::err_expected_class_or_namespace)
11406 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11407 return ExprError();
11408 }
11409 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11410 CCLoc);
11411 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011412
Abramo Bagnara7945c982012-01-27 09:46:47 +000011413 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011414 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011415 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011416 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011417 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011418 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011419 /*TemplateArgs*/ nullptr,
11420 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011421}
11422
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011423template<typename Derived>
11424StmtResult
11425TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011426 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011427 CapturedDecl *CD = S->getCapturedDecl();
11428 unsigned NumParams = CD->getNumParams();
11429 unsigned ContextParamPos = CD->getContextParamPosition();
11430 SmallVector<Sema::CapturedParamNameType, 4> Params;
11431 for (unsigned I = 0; I < NumParams; ++I) {
11432 if (I != ContextParamPos) {
11433 Params.push_back(
11434 std::make_pair(
11435 CD->getParam(I)->getName(),
11436 getDerived().TransformType(CD->getParam(I)->getType())));
11437 } else {
11438 Params.push_back(std::make_pair(StringRef(), QualType()));
11439 }
11440 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011441 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011442 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011443 StmtResult Body;
11444 {
11445 Sema::CompoundScopeRAII CompoundScope(getSema());
11446 Body = getDerived().TransformStmt(S->getCapturedStmt());
11447 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011448
11449 if (Body.isInvalid()) {
11450 getSema().ActOnCapturedRegionError();
11451 return StmtError();
11452 }
11453
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011454 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011455}
11456
Douglas Gregord6ff3322009-08-04 16:50:30 +000011457} // end namespace clang
11458
Hans Wennborg59dbe862015-09-29 20:56:43 +000011459#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H