blob: 200701e13dbb20715a17de63a3134641a98d7b83 [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
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001680 /// \brief Build a new OpenMP 'thread_limit' clause.
1681 ///
1682 /// By default, performs semantic analysis to build the new statement.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1685 SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1689 LParenLoc, EndLoc);
1690 }
1691
Alexey Bataeva0569352015-12-01 10:17:31 +00001692 /// \brief Build a new OpenMP 'priority' clause.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1697 SourceLocation LParenLoc,
1698 SourceLocation EndLoc) {
1699 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1700 EndLoc);
1701 }
1702
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001703 /// \brief Build a new OpenMP 'grainsize' clause.
1704 ///
1705 /// By default, performs semantic analysis to build the new statement.
1706 /// Subclasses may override this routine to provide different behavior.
1707 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1708 SourceLocation LParenLoc,
1709 SourceLocation EndLoc) {
1710 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1711 EndLoc);
1712 }
1713
Alexey Bataev382967a2015-12-08 12:06:20 +00001714 /// \brief Build a new OpenMP 'num_tasks' clause.
1715 ///
1716 /// By default, performs semantic analysis to build the new statement.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation EndLoc) {
1721 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1722 EndLoc);
1723 }
1724
Alexey Bataev28c75412015-12-15 08:19:24 +00001725 /// \brief Build a new OpenMP 'hint' clause.
1726 ///
1727 /// By default, performs semantic analysis to build the new statement.
1728 /// Subclasses may override this routine to provide different behavior.
1729 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1730 SourceLocation LParenLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1733 }
1734
James Dennett2a4d13c2012-06-15 07:13:21 +00001735 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001736 ///
1737 /// By default, performs semantic analysis to build the new statement.
1738 /// Subclasses may override this routine to provide different behavior.
1739 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1740 Expr *object) {
1741 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1742 }
1743
James Dennett2a4d13c2012-06-15 07:13:21 +00001744 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001745 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001746 /// By default, performs semantic analysis to build the new statement.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001749 Expr *Object, Stmt *Body) {
1750 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001751 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001752
James Dennett2a4d13c2012-06-15 07:13:21 +00001753 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001754 ///
1755 /// By default, performs semantic analysis to build the new statement.
1756 /// Subclasses may override this routine to provide different behavior.
1757 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1758 Stmt *Body) {
1759 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1760 }
John McCall53848232011-07-27 01:07:15 +00001761
Douglas Gregorf68a5082010-04-22 23:10:45 +00001762 /// \brief Build a new Objective-C fast enumeration statement.
1763 ///
1764 /// By default, performs semantic analysis to build the new statement.
1765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001766 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001767 Stmt *Element,
1768 Expr *Collection,
1769 SourceLocation RParenLoc,
1770 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001771 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001772 Element,
John McCallb268a282010-08-23 23:25:46 +00001773 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001774 RParenLoc);
1775 if (ForEachStmt.isInvalid())
1776 return StmtError();
1777
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001778 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001780
Douglas Gregorebe10102009-08-20 07:17:43 +00001781 /// \brief Build a new C++ exception declaration.
1782 ///
1783 /// By default, performs semantic analysis to build the new decaration.
1784 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001785 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001786 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001787 SourceLocation StartLoc,
1788 SourceLocation IdLoc,
1789 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001790 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001791 StartLoc, IdLoc, Id);
1792 if (Var)
1793 getSema().CurContext->addDecl(Var);
1794 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001795 }
1796
1797 /// \brief Build a new C++ catch statement.
1798 ///
1799 /// By default, performs semantic analysis to build the new statement.
1800 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001801 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001802 VarDecl *ExceptionDecl,
1803 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001804 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1805 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001806 }
Mike Stump11289f42009-09-09 15:08:12 +00001807
Douglas Gregorebe10102009-08-20 07:17:43 +00001808 /// \brief Build a new C++ try statement.
1809 ///
1810 /// By default, performs semantic analysis to build the new statement.
1811 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001812 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1813 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001814 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001815 }
Mike Stump11289f42009-09-09 15:08:12 +00001816
Richard Smith02e85f32011-04-14 22:09:26 +00001817 /// \brief Build a new C++0x range-based for statement.
1818 ///
1819 /// By default, performs semantic analysis to build the new statement.
1820 /// Subclasses may override this routine to provide different behavior.
1821 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001822 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001823 SourceLocation ColonLoc,
1824 Stmt *Range, Stmt *BeginEnd,
1825 Expr *Cond, Expr *Inc,
1826 Stmt *LoopVar,
1827 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001828 // If we've just learned that the range is actually an Objective-C
1829 // collection, treat this as an Objective-C fast enumeration loop.
1830 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1831 if (RangeStmt->isSingleDecl()) {
1832 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001833 if (RangeVar->isInvalidDecl())
1834 return StmtError();
1835
Douglas Gregorf7106af2013-04-08 18:40:13 +00001836 Expr *RangeExpr = RangeVar->getInit();
1837 if (!RangeExpr->isTypeDependent() &&
1838 RangeExpr->getType()->isObjCObjectPointerType())
1839 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1840 RParenLoc);
1841 }
1842 }
1843 }
1844
Richard Smithcfd53b42015-10-22 06:13:50 +00001845 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1846 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001847 Cond, Inc, LoopVar, RParenLoc,
1848 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001849 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001850
1851 /// \brief Build a new C++0x range-based for statement.
1852 ///
1853 /// By default, performs semantic analysis to build the new statement.
1854 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001855 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001856 bool IsIfExists,
1857 NestedNameSpecifierLoc QualifierLoc,
1858 DeclarationNameInfo NameInfo,
1859 Stmt *Nested) {
1860 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1861 QualifierLoc, NameInfo, Nested);
1862 }
1863
Richard Smith02e85f32011-04-14 22:09:26 +00001864 /// \brief Attach body to a C++0x range-based for statement.
1865 ///
1866 /// By default, performs semantic analysis to finish the new statement.
1867 /// Subclasses may override this routine to provide different behavior.
1868 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1869 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001871
David Majnemerfad8f482013-10-15 09:33:02 +00001872 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001873 Stmt *TryBlock, Stmt *Handler) {
1874 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001875 }
1876
David Majnemerfad8f482013-10-15 09:33:02 +00001877 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001878 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001879 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001880 }
1881
David Majnemerfad8f482013-10-15 09:33:02 +00001882 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001883 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001884 }
1885
Alexey Bataevec474782014-10-09 08:45:04 +00001886 /// \brief Build a new predefined expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
1890 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1891 PredefinedExpr::IdentType IT) {
1892 return getSema().BuildPredefinedExpr(Loc, IT);
1893 }
1894
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// \brief Build a new expression that references a declaration.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001900 LookupResult &R,
1901 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001902 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1903 }
1904
1905
1906 /// \brief Build a new expression that references a declaration.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001910 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001911 ValueDecl *VD,
1912 const DeclarationNameInfo &NameInfo,
1913 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001914 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001915 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001916
1917 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001918
1919 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
Mike Stump11289f42009-09-09 15:08:12 +00001921
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001923 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001928 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 }
1930
Douglas Gregorad8a3362009-09-04 17:36:40 +00001931 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001932 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001935 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001936 SourceLocation OperatorLoc,
1937 bool isArrow,
1938 CXXScopeSpec &SS,
1939 TypeSourceInfo *ScopeType,
1940 SourceLocation CCLoc,
1941 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001942 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001945 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001949 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001950 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001951 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 }
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregor882211c2010-04-28 22:16:22 +00001954 /// \brief Build a new builtin offsetof expression.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001958 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001959 TypeSourceInfo *Type,
1960 ArrayRef<Sema::OffsetOfComponent> Components,
1961 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001962 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001963 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001965
1966 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001967 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001968 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001971 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1972 SourceLocation OpLoc,
1973 UnaryExprOrTypeTrait ExprKind,
1974 SourceRange R) {
1975 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
1977
Peter Collingbournee190dee2011-03-11 19:24:49 +00001978 /// \brief Build a new sizeof, alignof or vec step expression with an
1979 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001980 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001983 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1984 UnaryExprOrTypeTrait ExprKind,
1985 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001986 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001987 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001990
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001991 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 }
Mike Stump11289f42009-09-09 15:08:12 +00001993
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001995 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001998 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002000 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002002 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002003 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 RBracketLoc);
2005 }
2006
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002007 /// \brief Build a new array section expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
2011 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2012 Expr *LowerBound,
2013 SourceLocation ColonLoc, Expr *Length,
2014 SourceLocation RBracketLoc) {
2015 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2016 ColonLoc, Length, RBracketLoc);
2017 }
2018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002020 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002025 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002026 Expr *ExecConfig = nullptr) {
2027 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002028 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
2030
2031 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002032 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002036 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002037 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002038 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002039 const DeclarationNameInfo &MemberNameInfo,
2040 ValueDecl *Member,
2041 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002042 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002043 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002044 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2045 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002046 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002047 // We have a reference to an unnamed field. This is always the
2048 // base of an anonymous struct/union member access, i.e. the
2049 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002050 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002051 assert(Member->getType()->isRecordType() &&
2052 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002053
Richard Smithcab9a7d2011-10-26 19:06:56 +00002054 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002055 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002056 QualifierLoc.getNestedNameSpecifier(),
2057 FoundDecl, Member);
2058 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002059 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002060 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002061 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002062 MemberExpr *ME = new (getSema().Context)
2063 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2064 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002065 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002068 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002069 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002070
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002071 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002072 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002073
John McCall16df1e52010-03-30 21:47:33 +00002074 // FIXME: this involves duplicating earlier analysis in a lot of
2075 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002076 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002077 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002078 R.resolveKind();
2079
John McCallb268a282010-08-23 23:25:46 +00002080 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002081 SS, TemplateKWLoc,
2082 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002083 R, ExplicitTemplateArgs,
2084 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002092 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002093 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002094 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
2096
2097 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002101 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002102 SourceLocation QuestionLoc,
2103 Expr *LHS,
2104 SourceLocation ColonLoc,
2105 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002106 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2107 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 }
2109
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002115 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002117 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002118 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002119 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 }
Mike Stump11289f42009-09-09 15:08:12 +00002121
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002126 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002127 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002129 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002130 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002131 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 }
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002135 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002138 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 SourceLocation OpLoc,
2140 SourceLocation AccessorLoc,
2141 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002142
John McCall10eae182009-11-30 22:42:35 +00002143 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002144 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002145 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002146 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002147 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002148 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002149 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002150 /* TemplateArgs */ nullptr,
2151 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 }
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002155 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002158 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002159 MultiExprArg Inits,
2160 SourceLocation RBraceLoc,
2161 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002163 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002164 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002165 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002166
Douglas Gregord3d93062009-11-09 17:16:50 +00002167 // Patch in the result type we were given, which may have been computed
2168 // when the initial InitListExpr was built.
2169 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2170 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002171 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002175 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 /// By default, performs semantic analysis to build the new expression.
2177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 MultiExprArg ArrayExprs,
2180 SourceLocation EqualOrColonLoc,
2181 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002182 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002185 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002188
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002189 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 }
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002193 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 /// By default, builds the implicit value initialization without performing
2195 /// any semantic analysis. Subclasses may override this routine to provide
2196 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002198 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002202 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002206 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002207 SourceLocation RParenLoc) {
2208 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002209 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002210 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 }
2212
2213 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002214 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 /// By default, performs semantic analysis to build the new expression.
2216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002217 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002218 MultiExprArg SubExprs,
2219 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002220 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
2225 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 /// rather than attempting to map the label statement itself.
2227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002228 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002229 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002230 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 }
Mike Stump11289f42009-09-09 15:08:12 +00002232
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002237 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002238 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002240 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 }
Mike Stump11289f42009-09-09 15:08:12 +00002242
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 /// \brief Build a new __builtin_choose_expr expression.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002247 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002248 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 SourceLocation RParenLoc) {
2250 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002251 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 RParenLoc);
2253 }
Mike Stump11289f42009-09-09 15:08:12 +00002254
Peter Collingbourne91147592011-04-15 00:35:48 +00002255 /// \brief Build a new generic selection expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
2259 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2260 SourceLocation DefaultLoc,
2261 SourceLocation RParenLoc,
2262 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002263 ArrayRef<TypeSourceInfo *> Types,
2264 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002265 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002266 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002267 }
2268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new overloaded operator call expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// The semantic analysis provides the behavior of template instantiation,
2273 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002274 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// argument-dependent lookup, etc. Subclasses may override this routine to
2276 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002279 Expr *Callee,
2280 Expr *First,
2281 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002282
2283 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// reinterpret_cast.
2285 ///
2286 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002287 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 Stmt::StmtClass Class,
2291 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) {
2297 switch (Class) {
2298 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002299 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002300 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002301 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002302
2303 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002304 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002305 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002306 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002307
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002309 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002310 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002311 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002313
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002315 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002316 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002317 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002320 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// \brief Build a new C++ static_cast expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002328 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002330 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 SourceLocation RAngleLoc,
2332 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002333 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002335 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002336 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002337 SourceRange(LAngleLoc, RAngleLoc),
2338 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 }
2340
2341 /// \brief Build a new C++ dynamic_cast expression.
2342 ///
2343 /// By default, performs semantic analysis to build the new expression.
2344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002345 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002347 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 SourceLocation RAngleLoc,
2349 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002350 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002352 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002353 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002354 SourceRange(LAngleLoc, RAngleLoc),
2355 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 }
2357
2358 /// \brief Build a new C++ reinterpret_cast expression.
2359 ///
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002362 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002364 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 SourceLocation RAngleLoc,
2366 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002367 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002369 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002370 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002371 SourceRange(LAngleLoc, RAngleLoc),
2372 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 }
2374
2375 /// \brief Build a new C++ const_cast expression.
2376 ///
2377 /// By default, performs semantic analysis to build the new expression.
2378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002379 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002381 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 SourceLocation RAngleLoc,
2383 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002384 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002386 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002387 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002388 SourceRange(LAngleLoc, RAngleLoc),
2389 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 /// \brief Build a new C++ functional-style cast expression.
2393 ///
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002396 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2397 SourceLocation LParenLoc,
2398 Expr *Sub,
2399 SourceLocation RParenLoc) {
2400 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002401 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 RParenLoc);
2403 }
Mike Stump11289f42009-09-09 15:08:12 +00002404
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 /// \brief Build a new C++ typeid(type) expression.
2406 ///
2407 /// By default, performs semantic analysis to build the new expression.
2408 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002409 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002410 SourceLocation TypeidLoc,
2411 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002413 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002414 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Francois Pichet9f4f2072010-09-08 12:20:18 +00002417
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 /// \brief Build a new C++ typeid(expr) expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002422 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002423 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002424 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002426 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002427 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002428 }
2429
Francois Pichet9f4f2072010-09-08 12:20:18 +00002430 /// \brief Build a new C++ __uuidof(type) expression.
2431 ///
2432 /// By default, performs semantic analysis to build the new expression.
2433 /// Subclasses may override this routine to provide different behavior.
2434 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2435 SourceLocation TypeidLoc,
2436 TypeSourceInfo *Operand,
2437 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002438 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002439 RParenLoc);
2440 }
2441
2442 /// \brief Build a new C++ __uuidof(expr) expression.
2443 ///
2444 /// By default, performs semantic analysis to build the new expression.
2445 /// Subclasses may override this routine to provide different behavior.
2446 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2447 SourceLocation TypeidLoc,
2448 Expr *Operand,
2449 SourceLocation RParenLoc) {
2450 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2451 RParenLoc);
2452 }
2453
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 /// \brief Build a new C++ "this" expression.
2455 ///
2456 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002457 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002460 QualType ThisType,
2461 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002462 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002463 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 }
2465
2466 /// \brief Build a new C++ throw expression.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002470 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2471 bool IsThrownVariableInScope) {
2472 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 }
2474
2475 /// \brief Build a new C++ default-argument expression.
2476 ///
2477 /// By default, builds a new default-argument expression, which does not
2478 /// require any semantic analysis. Subclasses may override this routine to
2479 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002480 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002481 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002482 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 }
2484
Richard Smith852c9db2013-04-20 22:23:05 +00002485 /// \brief Build a new C++11 default-initialization expression.
2486 ///
2487 /// By default, builds a new default field initialization expression, which
2488 /// does not require any semantic analysis. Subclasses may override this
2489 /// routine to provide different behavior.
2490 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2491 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002492 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002493 }
2494
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 /// \brief Build a new C++ zero-initialization expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002499 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2500 SourceLocation LParenLoc,
2501 SourceLocation RParenLoc) {
2502 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002503 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002504 }
Mike Stump11289f42009-09-09 15:08:12 +00002505
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 /// \brief Build a new C++ "new" expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002510 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002511 bool UseGlobal,
2512 SourceLocation PlacementLParen,
2513 MultiExprArg PlacementArgs,
2514 SourceLocation PlacementRParen,
2515 SourceRange TypeIdParens,
2516 QualType AllocatedType,
2517 TypeSourceInfo *AllocatedTypeInfo,
2518 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002519 SourceRange DirectInitRange,
2520 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002521 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002523 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002525 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002526 AllocatedType,
2527 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002528 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002529 DirectInitRange,
2530 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 }
Mike Stump11289f42009-09-09 15:08:12 +00002532
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 /// \brief Build a new C++ "delete" expression.
2534 ///
2535 /// By default, performs semantic analysis to build the new expression.
2536 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002537 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002538 bool IsGlobalDelete,
2539 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002540 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002542 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 }
Mike Stump11289f42009-09-09 15:08:12 +00002544
Douglas Gregor29c42f22012-02-24 07:38:34 +00002545 /// \brief Build a new type trait expression.
2546 ///
2547 /// By default, performs semantic analysis to build the new expression.
2548 /// Subclasses may override this routine to provide different behavior.
2549 ExprResult RebuildTypeTrait(TypeTrait Trait,
2550 SourceLocation StartLoc,
2551 ArrayRef<TypeSourceInfo *> Args,
2552 SourceLocation RParenLoc) {
2553 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2554 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002555
John Wiegley6242b6a2011-04-28 00:16:57 +00002556 /// \brief Build a new array type trait expression.
2557 ///
2558 /// By default, performs semantic analysis to build the new expression.
2559 /// Subclasses may override this routine to provide different behavior.
2560 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2561 SourceLocation StartLoc,
2562 TypeSourceInfo *TSInfo,
2563 Expr *DimExpr,
2564 SourceLocation RParenLoc) {
2565 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2566 }
2567
John Wiegleyf9f65842011-04-25 06:54:41 +00002568 /// \brief Build a new expression trait expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
2572 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2573 SourceLocation StartLoc,
2574 Expr *Queried,
2575 SourceLocation RParenLoc) {
2576 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2577 }
2578
Mike Stump11289f42009-09-09 15:08:12 +00002579 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 /// expression.
2581 ///
2582 /// By default, performs semantic analysis to build the new expression.
2583 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002584 ExprResult RebuildDependentScopeDeclRefExpr(
2585 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002586 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002587 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002588 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002589 bool IsAddressOfOperand,
2590 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002592 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002593
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002594 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002595 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2596 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002597
Reid Kleckner32506ed2014-06-12 23:03:48 +00002598 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002599 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 }
2601
2602 /// \brief Build a new template-id expression.
2603 ///
2604 /// By default, performs semantic analysis to build the new expression.
2605 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002606 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002607 SourceLocation TemplateKWLoc,
2608 LookupResult &R,
2609 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002610 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002611 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2612 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 }
2614
2615 /// \brief Build a new object-construction expression.
2616 ///
2617 /// By default, performs semantic analysis to build the new expression.
2618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002619 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002620 SourceLocation Loc,
2621 CXXConstructorDecl *Constructor,
2622 bool IsElidable,
2623 MultiExprArg Args,
2624 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002625 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002626 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002627 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002628 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002629 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002630 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002631 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002632 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002633 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002634
Douglas Gregordb121ba2009-12-14 16:27:04 +00002635 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002636 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002637 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002638 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002639 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002640 RequiresZeroInit, ConstructKind,
2641 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 }
2643
2644 /// \brief Build a new object-construction expression.
2645 ///
2646 /// By default, performs semantic analysis to build the new expression.
2647 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002648 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2649 SourceLocation LParenLoc,
2650 MultiExprArg Args,
2651 SourceLocation RParenLoc) {
2652 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002654 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002655 RParenLoc);
2656 }
2657
2658 /// \brief Build a new object-construction expression.
2659 ///
2660 /// By default, performs semantic analysis to build the new expression.
2661 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002662 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2663 SourceLocation LParenLoc,
2664 MultiExprArg Args,
2665 SourceLocation RParenLoc) {
2666 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002667 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002668 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 RParenLoc);
2670 }
Mike Stump11289f42009-09-09 15:08:12 +00002671
Douglas Gregora16548e2009-08-11 05:31:07 +00002672 /// \brief Build a new member reference expression.
2673 ///
2674 /// By default, performs semantic analysis to build the new expression.
2675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002676 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002677 QualType BaseType,
2678 bool IsArrow,
2679 SourceLocation OperatorLoc,
2680 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002681 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002682 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002683 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002684 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002685 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002686 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002687
John McCallb268a282010-08-23 23:25:46 +00002688 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002689 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002690 SS, TemplateKWLoc,
2691 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002692 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002693 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002694 }
2695
John McCall10eae182009-11-30 22:42:35 +00002696 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002697 ///
2698 /// By default, performs semantic analysis to build the new expression.
2699 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002700 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2701 SourceLocation OperatorLoc,
2702 bool IsArrow,
2703 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002704 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002705 NamedDecl *FirstQualifierInScope,
2706 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002707 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002708 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002709 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002710
John McCallb268a282010-08-23 23:25:46 +00002711 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002712 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002713 SS, TemplateKWLoc,
2714 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002715 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002716 }
Mike Stump11289f42009-09-09 15:08:12 +00002717
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002718 /// \brief Build a new noexcept expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
2722 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2723 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2724 }
2725
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002726 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002727 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2728 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002729 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002730 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002731 Optional<unsigned> Length,
2732 ArrayRef<TemplateArgument> PartialArgs) {
2733 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2734 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002735 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002736
Patrick Beard0caa3942012-04-19 00:25:12 +00002737 /// \brief Build a new Objective-C boxed expression.
2738 ///
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
2741 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2742 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002744
Ted Kremeneke65b0862012-03-06 20:05:56 +00002745 /// \brief Build a new Objective-C array literal.
2746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
2749 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2750 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002751 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002752 MultiExprArg(Elements, NumElements));
2753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002754
2755 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002756 Expr *Base, Expr *Key,
2757 ObjCMethodDecl *getterMethod,
2758 ObjCMethodDecl *setterMethod) {
2759 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2760 getterMethod, setterMethod);
2761 }
2762
2763 /// \brief Build a new Objective-C dictionary literal.
2764 ///
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
2767 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2768 ObjCDictionaryElement *Elements,
2769 unsigned NumElements) {
2770 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002772
James Dennett2a4d13c2012-06-15 07:13:21 +00002773 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002774 ///
2775 /// By default, performs semantic analysis to build the new expression.
2776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002777 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002778 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002779 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002780 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002781 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002782
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002783 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002784 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002785 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002786 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002787 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002788 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002789 MultiExprArg Args,
2790 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002791 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2792 ReceiverTypeInfo->getType(),
2793 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002794 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002795 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002796 }
2797
2798 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002799 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002800 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002801 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002802 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002803 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002804 MultiExprArg Args,
2805 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002806 return SemaRef.BuildInstanceMessage(Receiver,
2807 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002808 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002809 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002810 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002811 }
2812
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002813 /// \brief Build a new Objective-C instance/class message to 'super'.
2814 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2815 Selector Sel,
2816 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002817 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002818 ObjCMethodDecl *Method,
2819 SourceLocation LBracLoc,
2820 MultiExprArg Args,
2821 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002822 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002823 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002824 SuperLoc,
2825 Sel, Method, LBracLoc, SelectorLocs,
2826 RBracLoc, Args)
2827 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002828 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002829 SuperLoc,
2830 Sel, Method, LBracLoc, SelectorLocs,
2831 RBracLoc, Args);
2832
2833
2834 }
2835
Douglas Gregord51d90d2010-04-26 20:11:03 +00002836 /// \brief Build a new Objective-C ivar reference expression.
2837 ///
2838 /// By default, performs semantic analysis to build the new expression.
2839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002840 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002841 SourceLocation IvarLoc,
2842 bool IsArrow, bool IsFreeIvar) {
2843 // FIXME: We lose track of the IsFreeIvar bit.
2844 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002845 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2846 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002847 /*FIXME:*/IvarLoc, IsArrow,
2848 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002849 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002850 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002851 /*TemplateArgs=*/nullptr,
2852 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002853 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002854
2855 /// \brief Build a new Objective-C property reference expression.
2856 ///
2857 /// By default, performs semantic analysis to build the new expression.
2858 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002859 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002860 ObjCPropertyDecl *Property,
2861 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002862 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002863 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2864 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2865 /*FIXME:*/PropertyLoc,
2866 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002867 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002868 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002869 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002870 /*TemplateArgs=*/nullptr,
2871 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002873
John McCallb7bd14f2010-12-02 01:19:52 +00002874 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002875 ///
2876 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002877 /// Subclasses may override this routine to provide different behavior.
2878 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2879 ObjCMethodDecl *Getter,
2880 ObjCMethodDecl *Setter,
2881 SourceLocation PropertyLoc) {
2882 // Since these expressions can only be value-dependent, we do not
2883 // need to perform semantic analysis again.
2884 return Owned(
2885 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2886 VK_LValue, OK_ObjCProperty,
2887 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002888 }
2889
Douglas Gregord51d90d2010-04-26 20:11:03 +00002890 /// \brief Build a new Objective-C "isa" expression.
2891 ///
2892 /// By default, performs semantic analysis to build the new expression.
2893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002894 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002895 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002896 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002897 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2898 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002899 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002900 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002901 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002902 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002903 /*TemplateArgs=*/nullptr,
2904 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002906
Douglas Gregora16548e2009-08-11 05:31:07 +00002907 /// \brief Build a new shuffle vector expression.
2908 ///
2909 /// By default, performs semantic analysis to build the new expression.
2910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002911 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002912 MultiExprArg SubExprs,
2913 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002914 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002915 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002916 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2917 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2918 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002919 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002920
Douglas Gregora16548e2009-08-11 05:31:07 +00002921 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002922 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002923 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2924 SemaRef.Context.BuiltinFnTy,
2925 VK_RValue, BuiltinLoc);
2926 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2927 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002928 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002929
2930 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002931 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002932 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002933 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002934
Douglas Gregora16548e2009-08-11 05:31:07 +00002935 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002936 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002937 }
John McCall31f82722010-11-12 08:19:04 +00002938
Hal Finkelc4d7c822013-09-18 03:29:45 +00002939 /// \brief Build a new convert vector expression.
2940 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2941 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2942 SourceLocation RParenLoc) {
2943 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2944 BuiltinLoc, RParenLoc);
2945 }
2946
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002947 /// \brief Build a new template argument pack expansion.
2948 ///
2949 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002950 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002951 /// different behavior.
2952 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002953 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002954 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002955 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002956 case TemplateArgument::Expression: {
2957 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002958 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2959 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002960 if (Result.isInvalid())
2961 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002962
Douglas Gregor98318c22011-01-03 21:37:45 +00002963 return TemplateArgumentLoc(Result.get(), Result.get());
2964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002966 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002967 return TemplateArgumentLoc(TemplateArgument(
2968 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002969 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002970 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002971 Pattern.getTemplateNameLoc(),
2972 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002973
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002974 case TemplateArgument::Null:
2975 case TemplateArgument::Integral:
2976 case TemplateArgument::Declaration:
2977 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002978 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002979 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002980 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002982 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002983 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002984 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002985 EllipsisLoc,
2986 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2988 Expansion);
2989 break;
2990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002992 return TemplateArgumentLoc();
2993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
Douglas Gregor968f23a2011-01-03 19:31:53 +00002995 /// \brief Build a new expression pack expansion.
2996 ///
2997 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002998 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002999 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003000 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003001 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003002 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003003 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003004
Richard Smith0f0af192014-11-08 05:07:16 +00003005 /// \brief Build a new C++1z fold-expression.
3006 ///
3007 /// By default, performs semantic analysis in order to build a new fold
3008 /// expression.
3009 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3010 BinaryOperatorKind Operator,
3011 SourceLocation EllipsisLoc, Expr *RHS,
3012 SourceLocation RParenLoc) {
3013 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3014 RHS, RParenLoc);
3015 }
3016
3017 /// \brief Build an empty C++1z fold-expression with the given operator.
3018 ///
3019 /// By default, produces the fallback value for the fold-expression, or
3020 /// produce an error if there is no fallback value.
3021 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3022 BinaryOperatorKind Operator) {
3023 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3024 }
3025
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003026 /// \brief Build a new atomic operation expression.
3027 ///
3028 /// By default, performs semantic analysis to build the new expression.
3029 /// Subclasses may override this routine to provide different behavior.
3030 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3031 MultiExprArg SubExprs,
3032 QualType RetTy,
3033 AtomicExpr::AtomicOp Op,
3034 SourceLocation RParenLoc) {
3035 // Just create the expression; there is not any interesting semantic
3036 // analysis here because we can't actually build an AtomicExpr until
3037 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003038 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003039 RParenLoc);
3040 }
3041
John McCall31f82722010-11-12 08:19:04 +00003042private:
Douglas Gregor14454802011-02-25 02:25:35 +00003043 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3044 QualType ObjectType,
3045 NamedDecl *FirstQualifierInScope,
3046 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003047
3048 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3049 QualType ObjectType,
3050 NamedDecl *FirstQualifierInScope,
3051 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003052
3053 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3054 NamedDecl *FirstQualifierInScope,
3055 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003056};
Douglas Gregora16548e2009-08-11 05:31:07 +00003057
Douglas Gregorebe10102009-08-20 07:17:43 +00003058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003059StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003060 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003061 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003062
Douglas Gregorebe10102009-08-20 07:17:43 +00003063 switch (S->getStmtClass()) {
3064 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003065
Douglas Gregorebe10102009-08-20 07:17:43 +00003066 // Transform individual statement nodes
3067#define STMT(Node, Parent) \
3068 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003069#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003070#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003071#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 // Transform expressions by calling TransformExpr.
3074#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003075#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003076#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003077#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 {
John McCalldadc5752010-08-24 06:29:42 +00003079 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003080 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003081 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003082
Richard Smith945f8d32013-01-14 22:39:08 +00003083 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085 }
3086
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003087 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003088}
Mike Stump11289f42009-09-09 15:08:12 +00003089
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003090template<typename Derived>
3091OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3092 if (!S)
3093 return S;
3094
3095 switch (S->getClauseKind()) {
3096 default: break;
3097 // Transform individual clause nodes
3098#define OPENMP_CLAUSE(Name, Class) \
3099 case OMPC_ ## Name : \
3100 return getDerived().Transform ## Class(cast<Class>(S));
3101#include "clang/Basic/OpenMPKinds.def"
3102 }
3103
3104 return S;
3105}
3106
Mike Stump11289f42009-09-09 15:08:12 +00003107
Douglas Gregore922c772009-08-04 22:27:00 +00003108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003109ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003110 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003111 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003112
3113 switch (E->getStmtClass()) {
3114 case Stmt::NoStmtClass: break;
3115#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003116#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003117#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003118 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003119#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003120 }
3121
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003122 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003123}
3124
3125template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003126ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003127 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003128 // Initializers are instantiated like expressions, except that various outer
3129 // layers are stripped.
3130 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003131 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003132
3133 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3134 Init = ExprTemp->getSubExpr();
3135
Richard Smithe6ca4752013-05-30 22:40:16 +00003136 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3137 Init = MTE->GetTemporaryExpr();
3138
Richard Smithd59b8322012-12-19 01:39:02 +00003139 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3140 Init = Binder->getSubExpr();
3141
3142 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3143 Init = ICE->getSubExprAsWritten();
3144
Richard Smithcc1b96d2013-06-12 22:31:48 +00003145 if (CXXStdInitializerListExpr *ILE =
3146 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003147 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003148
Richard Smithc6abd962014-07-25 01:12:44 +00003149 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003150 // InitListExprs. Other forms of copy-initialization will be a no-op if
3151 // the initializer is already the right type.
3152 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003153 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003154 return getDerived().TransformExpr(Init);
3155
3156 // Revert value-initialization back to empty parens.
3157 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3158 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003159 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003160 Parens.getEnd());
3161 }
3162
3163 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3164 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003165 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003166 SourceLocation());
3167
3168 // Revert initialization by constructor back to a parenthesized or braced list
3169 // of expressions. Any other form of initializer can just be reused directly.
3170 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003171 return getDerived().TransformExpr(Init);
3172
Richard Smithf8adcdc2014-07-17 05:12:35 +00003173 // If the initialization implicitly converted an initializer list to a
3174 // std::initializer_list object, unwrap the std::initializer_list too.
3175 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003176 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003177
Richard Smithd59b8322012-12-19 01:39:02 +00003178 SmallVector<Expr*, 8> NewArgs;
3179 bool ArgChanged = false;
3180 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003181 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003182 return ExprError();
3183
3184 // If this was list initialization, revert to list form.
3185 if (Construct->isListInitialization())
3186 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3187 Construct->getLocEnd(),
3188 Construct->getType());
3189
Richard Smithd59b8322012-12-19 01:39:02 +00003190 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003191 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003192 if (Parens.isInvalid()) {
3193 // This was a variable declaration's initialization for which no initializer
3194 // was specified.
3195 assert(NewArgs.empty() &&
3196 "no parens or braces but have direct init with arguments?");
3197 return ExprEmpty();
3198 }
Richard Smithd59b8322012-12-19 01:39:02 +00003199 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3200 Parens.getEnd());
3201}
3202
3203template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003204bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3205 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003206 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003207 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003208 bool *ArgChanged) {
3209 for (unsigned I = 0; I != NumInputs; ++I) {
3210 // If requested, drop call arguments that need to be dropped.
3211 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3212 if (ArgChanged)
3213 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003214
Douglas Gregora3efea12011-01-03 19:04:46 +00003215 break;
3216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Douglas Gregor968f23a2011-01-03 19:31:53 +00003218 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3219 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003220
Chris Lattner01cf8db2011-07-20 06:58:45 +00003221 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003222 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3223 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003224
Douglas Gregor968f23a2011-01-03 19:31:53 +00003225 // Determine whether the set of unexpanded parameter packs can and should
3226 // be expanded.
3227 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003228 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003229 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3230 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003231 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3232 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003233 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003234 Expand, RetainExpansion,
3235 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003236 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003237
Douglas Gregor968f23a2011-01-03 19:31:53 +00003238 if (!Expand) {
3239 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003240 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003241 // expansion.
3242 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3243 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3244 if (OutPattern.isInvalid())
3245 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003246
3247 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003248 Expansion->getEllipsisLoc(),
3249 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003250 if (Out.isInvalid())
3251 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregor968f23a2011-01-03 19:31:53 +00003253 if (ArgChanged)
3254 *ArgChanged = true;
3255 Outputs.push_back(Out.get());
3256 continue;
3257 }
John McCall542e7c62011-07-06 07:30:07 +00003258
3259 // Record right away that the argument was changed. This needs
3260 // to happen even if the array expands to nothing.
3261 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor968f23a2011-01-03 19:31:53 +00003263 // The transform has determined that we should perform an elementwise
3264 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003265 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003266 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3267 ExprResult Out = getDerived().TransformExpr(Pattern);
3268 if (Out.isInvalid())
3269 return true;
3270
Richard Smith9467be42014-06-06 17:33:35 +00003271 // FIXME: Can this happen? We should not try to expand the pack
3272 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003273 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003274 Out = getDerived().RebuildPackExpansion(
3275 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003276 if (Out.isInvalid())
3277 return true;
3278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregor968f23a2011-01-03 19:31:53 +00003280 Outputs.push_back(Out.get());
3281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Richard Smith9467be42014-06-06 17:33:35 +00003283 // If we're supposed to retain a pack expansion, do so by temporarily
3284 // forgetting the partially-substituted parameter pack.
3285 if (RetainExpansion) {
3286 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3287
3288 ExprResult Out = getDerived().TransformExpr(Pattern);
3289 if (Out.isInvalid())
3290 return true;
3291
3292 Out = getDerived().RebuildPackExpansion(
3293 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3294 if (Out.isInvalid())
3295 return true;
3296
3297 Outputs.push_back(Out.get());
3298 }
3299
Douglas Gregor968f23a2011-01-03 19:31:53 +00003300 continue;
3301 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
Richard Smithd59b8322012-12-19 01:39:02 +00003303 ExprResult Result =
3304 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3305 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003306 if (Result.isInvalid())
3307 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregora3efea12011-01-03 19:04:46 +00003309 if (Result.get() != Inputs[I] && ArgChanged)
3310 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
3312 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregora3efea12011-01-03 19:04:46 +00003315 return false;
3316}
3317
3318template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003319NestedNameSpecifierLoc
3320TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3321 NestedNameSpecifierLoc NNS,
3322 QualType ObjectType,
3323 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003324 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003325 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003326 Qualifier = Qualifier.getPrefix())
3327 Qualifiers.push_back(Qualifier);
3328
3329 CXXScopeSpec SS;
3330 while (!Qualifiers.empty()) {
3331 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3332 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
Douglas Gregor14454802011-02-25 02:25:35 +00003334 switch (QNNS->getKind()) {
3335 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003336 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003337 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003338 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003339 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003340 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003341 FirstQualifierInScope, false))
3342 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor14454802011-02-25 02:25:35 +00003344 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor14454802011-02-25 02:25:35 +00003346 case NestedNameSpecifier::Namespace: {
3347 NamespaceDecl *NS
3348 = cast_or_null<NamespaceDecl>(
3349 getDerived().TransformDecl(
3350 Q.getLocalBeginLoc(),
3351 QNNS->getAsNamespace()));
3352 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3353 break;
3354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregor14454802011-02-25 02:25:35 +00003356 case NestedNameSpecifier::NamespaceAlias: {
3357 NamespaceAliasDecl *Alias
3358 = cast_or_null<NamespaceAliasDecl>(
3359 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3360 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003361 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003362 Q.getLocalEndLoc());
3363 break;
3364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003365
Douglas Gregor14454802011-02-25 02:25:35 +00003366 case NestedNameSpecifier::Global:
3367 // There is no meaningful transformation that one could perform on the
3368 // global scope.
3369 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3370 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Nikola Smiljanic67860242014-09-26 00:28:20 +00003372 case NestedNameSpecifier::Super: {
3373 CXXRecordDecl *RD =
3374 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3375 SourceLocation(), QNNS->getAsRecordDecl()));
3376 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3377 break;
3378 }
3379
Douglas Gregor14454802011-02-25 02:25:35 +00003380 case NestedNameSpecifier::TypeSpecWithTemplate:
3381 case NestedNameSpecifier::TypeSpec: {
3382 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3383 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor14454802011-02-25 02:25:35 +00003385 if (!TL)
3386 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor14454802011-02-25 02:25:35 +00003388 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003389 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003390 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003391 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003392 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003393 if (TL.getType()->isEnumeralType())
3394 SemaRef.Diag(TL.getBeginLoc(),
3395 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003396 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3397 Q.getLocalEndLoc());
3398 break;
3399 }
Richard Trieude756fb2011-05-07 01:36:37 +00003400 // If the nested-name-specifier is an invalid type def, don't emit an
3401 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003402 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3403 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003404 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003405 << TL.getType() << SS.getRange();
3406 }
Douglas Gregor14454802011-02-25 02:25:35 +00003407 return NestedNameSpecifierLoc();
3408 }
Douglas Gregore16af532011-02-28 18:50:33 +00003409 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
Douglas Gregore16af532011-02-28 18:50:33 +00003411 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003412 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003413 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor14454802011-02-25 02:25:35 +00003416 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003417 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003418 !getDerived().AlwaysRebuild())
3419 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
3421 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003422 // nested-name-specifier, do so.
3423 if (SS.location_size() == NNS.getDataLength() &&
3424 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3425 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3426
3427 // Allocate new nested-name-specifier location information.
3428 return SS.getWithLocInContext(SemaRef.Context);
3429}
3430
3431template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003432DeclarationNameInfo
3433TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003434::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003435 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003436 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003437 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003438
3439 switch (Name.getNameKind()) {
3440 case DeclarationName::Identifier:
3441 case DeclarationName::ObjCZeroArgSelector:
3442 case DeclarationName::ObjCOneArgSelector:
3443 case DeclarationName::ObjCMultiArgSelector:
3444 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003445 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003446 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003447 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregorf816bd72009-09-03 22:13:48 +00003449 case DeclarationName::CXXConstructorName:
3450 case DeclarationName::CXXDestructorName:
3451 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003452 TypeSourceInfo *NewTInfo;
3453 CanQualType NewCanTy;
3454 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003455 NewTInfo = getDerived().TransformType(OldTInfo);
3456 if (!NewTInfo)
3457 return DeclarationNameInfo();
3458 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003459 }
3460 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003461 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003462 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003463 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003464 if (NewT.isNull())
3465 return DeclarationNameInfo();
3466 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3467 }
Mike Stump11289f42009-09-09 15:08:12 +00003468
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003469 DeclarationName NewName
3470 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3471 NewCanTy);
3472 DeclarationNameInfo NewNameInfo(NameInfo);
3473 NewNameInfo.setName(NewName);
3474 NewNameInfo.setNamedTypeInfo(NewTInfo);
3475 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003476 }
Mike Stump11289f42009-09-09 15:08:12 +00003477 }
3478
David Blaikie83d382b2011-09-23 05:06:16 +00003479 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003480}
3481
3482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003483TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003484TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3485 TemplateName Name,
3486 SourceLocation NameLoc,
3487 QualType ObjectType,
3488 NamedDecl *FirstQualifierInScope) {
3489 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3490 TemplateDecl *Template = QTN->getTemplateDecl();
3491 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregor9db53502011-03-02 18:07:45 +00003493 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003494 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003495 Template));
3496 if (!TransTemplate)
3497 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor9db53502011-03-02 18:07:45 +00003499 if (!getDerived().AlwaysRebuild() &&
3500 SS.getScopeRep() == QTN->getQualifier() &&
3501 TransTemplate == Template)
3502 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Douglas Gregor9db53502011-03-02 18:07:45 +00003504 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3505 TransTemplate);
3506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregor9db53502011-03-02 18:07:45 +00003508 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3509 if (SS.getScopeRep()) {
3510 // These apply to the scope specifier, not the template.
3511 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003512 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003513 }
3514
Douglas Gregor9db53502011-03-02 18:07:45 +00003515 if (!getDerived().AlwaysRebuild() &&
3516 SS.getScopeRep() == DTN->getQualifier() &&
3517 ObjectType.isNull())
3518 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregor9db53502011-03-02 18:07:45 +00003520 if (DTN->isIdentifier()) {
3521 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003522 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003523 NameLoc,
3524 ObjectType,
3525 FirstQualifierInScope);
3526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
Douglas Gregor9db53502011-03-02 18:07:45 +00003528 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3529 ObjectType);
3530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregor9db53502011-03-02 18:07:45 +00003532 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3533 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003534 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003535 Template));
3536 if (!TransTemplate)
3537 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003538
Douglas Gregor9db53502011-03-02 18:07:45 +00003539 if (!getDerived().AlwaysRebuild() &&
3540 TransTemplate == Template)
3541 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregor9db53502011-03-02 18:07:45 +00003543 return TemplateName(TransTemplate);
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor9db53502011-03-02 18:07:45 +00003546 if (SubstTemplateTemplateParmPackStorage *SubstPack
3547 = Name.getAsSubstTemplateTemplateParmPack()) {
3548 TemplateTemplateParmDecl *TransParam
3549 = cast_or_null<TemplateTemplateParmDecl>(
3550 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3551 if (!TransParam)
3552 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor9db53502011-03-02 18:07:45 +00003554 if (!getDerived().AlwaysRebuild() &&
3555 TransParam == SubstPack->getParameterPack())
3556 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003557
3558 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003559 SubstPack->getArgumentPack());
3560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor9db53502011-03-02 18:07:45 +00003562 // These should be getting filtered out before they reach the AST.
3563 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003564}
3565
3566template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003567void TreeTransform<Derived>::InventTemplateArgumentLoc(
3568 const TemplateArgument &Arg,
3569 TemplateArgumentLoc &Output) {
3570 SourceLocation Loc = getDerived().getBaseLocation();
3571 switch (Arg.getKind()) {
3572 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003573 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003574 break;
3575
3576 case TemplateArgument::Type:
3577 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003578 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
John McCall0ad16662009-10-29 08:12:44 +00003580 break;
3581
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003582 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003583 case TemplateArgument::TemplateExpansion: {
3584 NestedNameSpecifierLocBuilder Builder;
3585 TemplateName Template = Arg.getAsTemplate();
3586 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3587 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3588 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3589 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Douglas Gregor9d802122011-03-02 17:09:35 +00003591 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003592 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003593 Builder.getWithLocInContext(SemaRef.Context),
3594 Loc);
3595 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003596 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003597 Builder.getWithLocInContext(SemaRef.Context),
3598 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003600 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003601 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003602
John McCall0ad16662009-10-29 08:12:44 +00003603 case TemplateArgument::Expression:
3604 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3605 break;
3606
3607 case TemplateArgument::Declaration:
3608 case TemplateArgument::Integral:
3609 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003610 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003611 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003612 break;
3613 }
3614}
3615
3616template<typename Derived>
3617bool TreeTransform<Derived>::TransformTemplateArgument(
3618 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003619 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003620 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003621 switch (Arg.getKind()) {
3622 case TemplateArgument::Null:
3623 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003624 case TemplateArgument::Pack:
3625 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003626 case TemplateArgument::NullPtr:
3627 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregore922c772009-08-04 22:27:00 +00003629 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003630 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003631 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003632 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003633
3634 DI = getDerived().TransformType(DI);
3635 if (!DI) return true;
3636
3637 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3638 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003639 }
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003641 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003642 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3643 if (QualifierLoc) {
3644 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3645 if (!QualifierLoc)
3646 return true;
3647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregordf846d12011-03-02 18:46:51 +00003649 CXXScopeSpec SS;
3650 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003651 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003652 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3653 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003654 if (Template.isNull())
3655 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003656
Douglas Gregor9d802122011-03-02 17:09:35 +00003657 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003658 Input.getTemplateNameLoc());
3659 return false;
3660 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003661
3662 case TemplateArgument::TemplateExpansion:
3663 llvm_unreachable("Caller should expand pack expansions");
3664
Douglas Gregore922c772009-08-04 22:27:00 +00003665 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003666 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003667 EnterExpressionEvaluationContext Unevaluated(
3668 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003669
John McCall0ad16662009-10-29 08:12:44 +00003670 Expr *InputExpr = Input.getSourceExpression();
3671 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3672
Chris Lattnercdb591a2011-04-25 20:37:58 +00003673 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003674 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003675 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003676 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003677 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003678 }
Douglas Gregore922c772009-08-04 22:27:00 +00003679 }
Mike Stump11289f42009-09-09 15:08:12 +00003680
Douglas Gregore922c772009-08-04 22:27:00 +00003681 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003682 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003683}
3684
Douglas Gregorfe921a72010-12-20 23:36:19 +00003685/// \brief Iterator adaptor that invents template argument location information
3686/// for each of the template arguments in its underlying iterator.
3687template<typename Derived, typename InputIterator>
3688class TemplateArgumentLocInventIterator {
3689 TreeTransform<Derived> &Self;
3690 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregorfe921a72010-12-20 23:36:19 +00003692public:
3693 typedef TemplateArgumentLoc value_type;
3694 typedef TemplateArgumentLoc reference;
3695 typedef typename std::iterator_traits<InputIterator>::difference_type
3696 difference_type;
3697 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregorfe921a72010-12-20 23:36:19 +00003699 class pointer {
3700 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003701
Douglas Gregorfe921a72010-12-20 23:36:19 +00003702 public:
3703 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003704
Douglas Gregorfe921a72010-12-20 23:36:19 +00003705 const TemplateArgumentLoc *operator->() const { return &Arg; }
3706 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003708 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003709
Douglas Gregorfe921a72010-12-20 23:36:19 +00003710 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3711 InputIterator Iter)
3712 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
Douglas Gregorfe921a72010-12-20 23:36:19 +00003714 TemplateArgumentLocInventIterator &operator++() {
3715 ++Iter;
3716 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Douglas Gregorfe921a72010-12-20 23:36:19 +00003719 TemplateArgumentLocInventIterator operator++(int) {
3720 TemplateArgumentLocInventIterator Old(*this);
3721 ++(*this);
3722 return Old;
3723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
Douglas Gregorfe921a72010-12-20 23:36:19 +00003725 reference operator*() const {
3726 TemplateArgumentLoc Result;
3727 Self.InventTemplateArgumentLoc(*Iter, Result);
3728 return Result;
3729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Douglas Gregorfe921a72010-12-20 23:36:19 +00003731 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Douglas Gregorfe921a72010-12-20 23:36:19 +00003733 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3734 const TemplateArgumentLocInventIterator &Y) {
3735 return X.Iter == Y.Iter;
3736 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003737
Douglas Gregorfe921a72010-12-20 23:36:19 +00003738 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3739 const TemplateArgumentLocInventIterator &Y) {
3740 return X.Iter != Y.Iter;
3741 }
3742};
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor42cafa82010-12-20 17:42:22 +00003744template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003745template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003746bool TreeTransform<Derived>::TransformTemplateArguments(
3747 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3748 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003749 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003750 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003751 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003753 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3754 // Unpack argument packs, which we translate them into separate
3755 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003756 // FIXME: We could do much better if we could guarantee that the
3757 // TemplateArgumentLocInfo for the pack expansion would be usable for
3758 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003759 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003760 TemplateArgument::pack_iterator>
3761 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003762 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003763 In.getArgument().pack_begin()),
3764 PackLocIterator(*this,
3765 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003766 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003767 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003768
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003769 continue;
3770 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003771
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003772 if (In.getArgument().isPackExpansion()) {
3773 // We have a pack expansion, for which we will be substituting into
3774 // the pattern.
3775 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003776 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003777 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003778 = getSema().getTemplateArgumentPackExpansionPattern(
3779 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Chris Lattner01cf8db2011-07-20 06:58:45 +00003781 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003782 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3783 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003784
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003785 // Determine whether the set of unexpanded parameter packs can and should
3786 // be expanded.
3787 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003788 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003789 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003790 if (getDerived().TryExpandParameterPacks(Ellipsis,
3791 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003792 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003793 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003794 RetainExpansion,
3795 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003796 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003798 if (!Expand) {
3799 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003800 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003801 // expansion.
3802 TemplateArgumentLoc OutPattern;
3803 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003804 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003805 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003806
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003807 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3808 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003809 if (Out.getArgument().isNull())
3810 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003812 Outputs.addArgument(Out);
3813 continue;
3814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003815
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003816 // The transform has determined that we should perform an elementwise
3817 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003818 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003819 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3820
Richard Smithd784e682015-09-23 21:41:42 +00003821 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003822 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003823
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003824 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003825 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3826 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003827 if (Out.getArgument().isNull())
3828 return true;
3829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003831 Outputs.addArgument(Out);
3832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003833
Douglas Gregor48d24112011-01-10 20:53:55 +00003834 // If we're supposed to retain a pack expansion, do so by temporarily
3835 // forgetting the partially-substituted parameter pack.
3836 if (RetainExpansion) {
3837 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003838
Richard Smithd784e682015-09-23 21:41:42 +00003839 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003840 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003842 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3843 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003844 if (Out.getArgument().isNull())
3845 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846
Douglas Gregor48d24112011-01-10 20:53:55 +00003847 Outputs.addArgument(Out);
3848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003849
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003850 continue;
3851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003852
3853 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003854 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003855 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003856
Douglas Gregor42cafa82010-12-20 17:42:22 +00003857 Outputs.addArgument(Out);
3858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor42cafa82010-12-20 17:42:22 +00003860 return false;
3861
3862}
3863
Douglas Gregord6ff3322009-08-04 16:50:30 +00003864//===----------------------------------------------------------------------===//
3865// Type transformation
3866//===----------------------------------------------------------------------===//
3867
3868template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003869QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003870 if (getDerived().AlreadyTransformed(T))
3871 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003872
John McCall550e0c22009-10-21 00:40:46 +00003873 // Temporary workaround. All of these transformations should
3874 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003875 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3876 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
John McCall31f82722010-11-12 08:19:04 +00003878 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003879
John McCall550e0c22009-10-21 00:40:46 +00003880 if (!NewDI)
3881 return QualType();
3882
3883 return NewDI->getType();
3884}
3885
3886template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003887TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003888 // Refine the base location to the type's location.
3889 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3890 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003891 if (getDerived().AlreadyTransformed(DI->getType()))
3892 return DI;
3893
3894 TypeLocBuilder TLB;
3895
3896 TypeLoc TL = DI->getTypeLoc();
3897 TLB.reserve(TL.getFullDataSize());
3898
John McCall31f82722010-11-12 08:19:04 +00003899 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003900 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003901 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003902
John McCallbcd03502009-12-07 02:54:59 +00003903 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003904}
3905
3906template<typename Derived>
3907QualType
John McCall31f82722010-11-12 08:19:04 +00003908TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003909 switch (T.getTypeLocClass()) {
3910#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003911#define TYPELOC(CLASS, PARENT) \
3912 case TypeLoc::CLASS: \
3913 return getDerived().Transform##CLASS##Type(TLB, \
3914 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003915#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003916 }
Mike Stump11289f42009-09-09 15:08:12 +00003917
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003918 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003919}
3920
3921/// FIXME: By default, this routine adds type qualifiers only to types
3922/// that can have qualifiers, and silently suppresses those qualifiers
3923/// that are not permitted (e.g., qualifiers on reference or function
3924/// types). This is the right thing for template instantiation, but
3925/// probably not for other clients.
3926template<typename Derived>
3927QualType
3928TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003929 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003930 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003931
John McCall31f82722010-11-12 08:19:04 +00003932 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003933 if (Result.isNull())
3934 return QualType();
3935
3936 // Silently suppress qualifiers if the result type can't be qualified.
3937 // FIXME: this is the right thing for template instantiation, but
3938 // probably not for other clients.
3939 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003940 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003941
John McCall31168b02011-06-15 23:02:42 +00003942 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003943 // resulting type.
3944 if (Quals.hasObjCLifetime()) {
3945 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3946 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003947 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003948 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003949 // A lifetime qualifier applied to a substituted template parameter
3950 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003951 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003952 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003953 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3954 QualType Replacement = SubstTypeParam->getReplacementType();
3955 Qualifiers Qs = Replacement.getQualifiers();
3956 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003957 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003958 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3959 Qs);
3960 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003961 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003962 Replacement);
3963 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003964 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3965 // 'auto' types behave the same way as template parameters.
3966 QualType Deduced = AutoTy->getDeducedType();
3967 Qualifiers Qs = Deduced.getQualifiers();
3968 Qs.removeObjCLifetime();
3969 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3970 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003971 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003972 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003973 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003974 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003975 // Otherwise, complain about the addition of a qualifier to an
3976 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003977 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003978 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003979 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003980
Douglas Gregore46db902011-06-17 22:11:49 +00003981 Quals.removeObjCLifetime();
3982 }
3983 }
3984 }
John McCallcb0f89a2010-06-05 06:41:15 +00003985 if (!Quals.empty()) {
3986 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003987 // BuildQualifiedType might not add qualifiers if they are invalid.
3988 if (Result.hasLocalQualifiers())
3989 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003990 // No location information to preserve.
3991 }
John McCall550e0c22009-10-21 00:40:46 +00003992
3993 return Result;
3994}
3995
Douglas Gregor14454802011-02-25 02:25:35 +00003996template<typename Derived>
3997TypeLoc
3998TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3999 QualType ObjectType,
4000 NamedDecl *UnqualLookup,
4001 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004002 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004003 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004004
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004005 TypeSourceInfo *TSI =
4006 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4007 if (TSI)
4008 return TSI->getTypeLoc();
4009 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004010}
4011
Douglas Gregor579c15f2011-03-02 18:32:08 +00004012template<typename Derived>
4013TypeSourceInfo *
4014TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4015 QualType ObjectType,
4016 NamedDecl *UnqualLookup,
4017 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004018 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004019 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004020
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004021 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4022 UnqualLookup, SS);
4023}
4024
4025template <typename Derived>
4026TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4027 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4028 CXXScopeSpec &SS) {
4029 QualType T = TL.getType();
4030 assert(!getDerived().AlreadyTransformed(T));
4031
Douglas Gregor579c15f2011-03-02 18:32:08 +00004032 TypeLocBuilder TLB;
4033 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004034
Douglas Gregor579c15f2011-03-02 18:32:08 +00004035 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004036 TemplateSpecializationTypeLoc SpecTL =
4037 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Douglas Gregor579c15f2011-03-02 18:32:08 +00004039 TemplateName Template
4040 = getDerived().TransformTemplateName(SS,
4041 SpecTL.getTypePtr()->getTemplateName(),
4042 SpecTL.getTemplateNameLoc(),
4043 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004044 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004045 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
4047 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004048 Template);
4049 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004050 DependentTemplateSpecializationTypeLoc SpecTL =
4051 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004052
Douglas Gregor579c15f2011-03-02 18:32:08 +00004053 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004054 = getDerived().RebuildTemplateName(SS,
4055 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004056 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004057 ObjectType, UnqualLookup);
4058 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004059 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004060
4061 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004062 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004063 Template,
4064 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004065 } else {
4066 // Nothing special needs to be done for these.
4067 Result = getDerived().TransformType(TLB, TL);
4068 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004069
4070 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004071 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004072
Douglas Gregor579c15f2011-03-02 18:32:08 +00004073 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4074}
4075
John McCall550e0c22009-10-21 00:40:46 +00004076template <class TyLoc> static inline
4077QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4078 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4079 NewT.setNameLoc(T.getNameLoc());
4080 return T.getType();
4081}
4082
John McCall550e0c22009-10-21 00:40:46 +00004083template<typename Derived>
4084QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004086 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4087 NewT.setBuiltinLoc(T.getBuiltinLoc());
4088 if (T.needsExtraLocalData())
4089 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4090 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004091}
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004094QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004096 // FIXME: recurse?
4097 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004098}
Mike Stump11289f42009-09-09 15:08:12 +00004099
Reid Kleckner0503a872013-12-05 01:23:43 +00004100template <typename Derived>
4101QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4102 AdjustedTypeLoc TL) {
4103 // Adjustments applied during transformation are handled elsewhere.
4104 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4105}
4106
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004108QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4109 DecayedTypeLoc TL) {
4110 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4111 if (OriginalType.isNull())
4112 return QualType();
4113
4114 QualType Result = TL.getType();
4115 if (getDerived().AlwaysRebuild() ||
4116 OriginalType != TL.getOriginalLoc().getType())
4117 Result = SemaRef.Context.getDecayedType(OriginalType);
4118 TLB.push<DecayedTypeLoc>(Result);
4119 // Nothing to set for DecayedTypeLoc.
4120 return Result;
4121}
4122
4123template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004124QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004125 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004126 QualType PointeeType
4127 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004128 if (PointeeType.isNull())
4129 return QualType();
4130
4131 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004132 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004133 // A dependent pointer type 'T *' has is being transformed such
4134 // that an Objective-C class type is being replaced for 'T'. The
4135 // resulting pointer type is an ObjCObjectPointerType, not a
4136 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004137 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004138
John McCall8b07ec22010-05-15 11:32:37 +00004139 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4140 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004141 return Result;
4142 }
John McCall31f82722010-11-12 08:19:04 +00004143
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004144 if (getDerived().AlwaysRebuild() ||
4145 PointeeType != TL.getPointeeLoc().getType()) {
4146 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4147 if (Result.isNull())
4148 return QualType();
4149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
John McCall31168b02011-06-15 23:02:42 +00004151 // Objective-C ARC can add lifetime qualifiers to the type that we're
4152 // pointing to.
4153 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004155 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4156 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004157 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
4160template<typename Derived>
4161QualType
John McCall550e0c22009-10-21 00:40:46 +00004162TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004163 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004164 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004165 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4166 if (PointeeType.isNull())
4167 return QualType();
4168
4169 QualType Result = TL.getType();
4170 if (getDerived().AlwaysRebuild() ||
4171 PointeeType != TL.getPointeeLoc().getType()) {
4172 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004173 TL.getSigilLoc());
4174 if (Result.isNull())
4175 return QualType();
4176 }
4177
Douglas Gregor049211a2010-04-22 16:50:51 +00004178 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004179 NewT.setSigilLoc(TL.getSigilLoc());
4180 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004181}
4182
John McCall70dd5f62009-10-30 00:06:24 +00004183/// Transforms a reference type. Note that somewhat paradoxically we
4184/// don't care whether the type itself is an l-value type or an r-value
4185/// type; we only care if the type was *written* as an l-value type
4186/// or an r-value type.
4187template<typename Derived>
4188QualType
4189TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004191 const ReferenceType *T = TL.getTypePtr();
4192
4193 // Note that this works with the pointee-as-written.
4194 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4195 if (PointeeType.isNull())
4196 return QualType();
4197
4198 QualType Result = TL.getType();
4199 if (getDerived().AlwaysRebuild() ||
4200 PointeeType != T->getPointeeTypeAsWritten()) {
4201 Result = getDerived().RebuildReferenceType(PointeeType,
4202 T->isSpelledAsLValue(),
4203 TL.getSigilLoc());
4204 if (Result.isNull())
4205 return QualType();
4206 }
4207
John McCall31168b02011-06-15 23:02:42 +00004208 // Objective-C ARC can add lifetime qualifiers to the type that we're
4209 // referring to.
4210 TLB.TypeWasModifiedSafely(
4211 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4212
John McCall70dd5f62009-10-30 00:06:24 +00004213 // r-value references can be rebuilt as l-value references.
4214 ReferenceTypeLoc NewTL;
4215 if (isa<LValueReferenceType>(Result))
4216 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4217 else
4218 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4219 NewTL.setSigilLoc(TL.getSigilLoc());
4220
4221 return Result;
4222}
4223
Mike Stump11289f42009-09-09 15:08:12 +00004224template<typename Derived>
4225QualType
John McCall550e0c22009-10-21 00:40:46 +00004226TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004227 LValueReferenceTypeLoc TL) {
4228 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004229}
4230
Mike Stump11289f42009-09-09 15:08:12 +00004231template<typename Derived>
4232QualType
John McCall550e0c22009-10-21 00:40:46 +00004233TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004234 RValueReferenceTypeLoc TL) {
4235 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236}
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregord6ff3322009-08-04 16:50:30 +00004238template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004239QualType
John McCall550e0c22009-10-21 00:40:46 +00004240TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004242 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004243 if (PointeeType.isNull())
4244 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004245
Abramo Bagnara509357842011-03-05 14:42:21 +00004246 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004247 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004248 if (OldClsTInfo) {
4249 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4250 if (!NewClsTInfo)
4251 return QualType();
4252 }
4253
4254 const MemberPointerType *T = TL.getTypePtr();
4255 QualType OldClsType = QualType(T->getClass(), 0);
4256 QualType NewClsType;
4257 if (NewClsTInfo)
4258 NewClsType = NewClsTInfo->getType();
4259 else {
4260 NewClsType = getDerived().TransformType(OldClsType);
4261 if (NewClsType.isNull())
4262 return QualType();
4263 }
Mike Stump11289f42009-09-09 15:08:12 +00004264
John McCall550e0c22009-10-21 00:40:46 +00004265 QualType Result = TL.getType();
4266 if (getDerived().AlwaysRebuild() ||
4267 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004268 NewClsType != OldClsType) {
4269 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004270 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004271 if (Result.isNull())
4272 return QualType();
4273 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004274
Reid Kleckner0503a872013-12-05 01:23:43 +00004275 // If we had to adjust the pointee type when building a member pointer, make
4276 // sure to push TypeLoc info for it.
4277 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4278 if (MPT && PointeeType != MPT->getPointeeType()) {
4279 assert(isa<AdjustedType>(MPT->getPointeeType()));
4280 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4281 }
4282
John McCall550e0c22009-10-21 00:40:46 +00004283 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4284 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004285 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004286
4287 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004288}
4289
Mike Stump11289f42009-09-09 15:08:12 +00004290template<typename Derived>
4291QualType
John McCall550e0c22009-10-21 00:40:46 +00004292TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004293 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004294 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004295 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296 if (ElementType.isNull())
4297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004298
John McCall550e0c22009-10-21 00:40:46 +00004299 QualType Result = TL.getType();
4300 if (getDerived().AlwaysRebuild() ||
4301 ElementType != T->getElementType()) {
4302 Result = getDerived().RebuildConstantArrayType(ElementType,
4303 T->getSizeModifier(),
4304 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004305 T->getIndexTypeCVRQualifiers(),
4306 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004307 if (Result.isNull())
4308 return QualType();
4309 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004310
4311 // We might have either a ConstantArrayType or a VariableArrayType now:
4312 // a ConstantArrayType is allowed to have an element type which is a
4313 // VariableArrayType if the type is dependent. Fortunately, all array
4314 // types have the same location layout.
4315 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004316 NewTL.setLBracketLoc(TL.getLBracketLoc());
4317 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004318
John McCall550e0c22009-10-21 00:40:46 +00004319 Expr *Size = TL.getSizeExpr();
4320 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004321 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4322 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004323 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4324 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004325 }
4326 NewTL.setSizeExpr(Size);
4327
4328 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregord6ff3322009-08-04 16:50:30 +00004331template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004332QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004333 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004335 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004336 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004337 if (ElementType.isNull())
4338 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004339
John McCall550e0c22009-10-21 00:40:46 +00004340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() ||
4342 ElementType != T->getElementType()) {
4343 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004344 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004345 T->getIndexTypeCVRQualifiers(),
4346 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004347 if (Result.isNull())
4348 return QualType();
4349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004350
John McCall550e0c22009-10-21 00:40:46 +00004351 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4352 NewTL.setLBracketLoc(TL.getLBracketLoc());
4353 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004354 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004355
4356 return Result;
4357}
4358
4359template<typename Derived>
4360QualType
4361TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004362 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004363 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004364 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4365 if (ElementType.isNull())
4366 return QualType();
4367
John McCalldadc5752010-08-24 06:29:42 +00004368 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004369 = getDerived().TransformExpr(T->getSizeExpr());
4370 if (SizeResult.isInvalid())
4371 return QualType();
4372
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004373 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004374
4375 QualType Result = TL.getType();
4376 if (getDerived().AlwaysRebuild() ||
4377 ElementType != T->getElementType() ||
4378 Size != T->getSizeExpr()) {
4379 Result = getDerived().RebuildVariableArrayType(ElementType,
4380 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004381 Size,
John McCall550e0c22009-10-21 00:40:46 +00004382 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004383 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004384 if (Result.isNull())
4385 return QualType();
4386 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
Serge Pavlov774c6d02014-02-06 03:49:11 +00004388 // We might have constant size array now, but fortunately it has the same
4389 // location layout.
4390 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004391 NewTL.setLBracketLoc(TL.getLBracketLoc());
4392 NewTL.setRBracketLoc(TL.getRBracketLoc());
4393 NewTL.setSizeExpr(Size);
4394
4395 return Result;
4396}
4397
4398template<typename Derived>
4399QualType
4400TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004401 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004402 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004403 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4404 if (ElementType.isNull())
4405 return QualType();
4406
Richard Smith764d2fe2011-12-20 02:08:33 +00004407 // Array bounds are constant expressions.
4408 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4409 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004410
John McCall33ddac02011-01-19 10:06:00 +00004411 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4412 Expr *origSize = TL.getSizeExpr();
4413 if (!origSize) origSize = T->getSizeExpr();
4414
4415 ExprResult sizeResult
4416 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004417 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004418 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004419 return QualType();
4420
John McCall33ddac02011-01-19 10:06:00 +00004421 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004422
4423 QualType Result = TL.getType();
4424 if (getDerived().AlwaysRebuild() ||
4425 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004426 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004427 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4428 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004429 size,
John McCall550e0c22009-10-21 00:40:46 +00004430 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004431 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004432 if (Result.isNull())
4433 return QualType();
4434 }
John McCall550e0c22009-10-21 00:40:46 +00004435
4436 // We might have any sort of array type now, but fortunately they
4437 // all have the same location layout.
4438 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4439 NewTL.setLBracketLoc(TL.getLBracketLoc());
4440 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004441 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004442
4443 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004444}
Mike Stump11289f42009-09-09 15:08:12 +00004445
4446template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004448 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004449 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004450 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004451
4452 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004453 QualType ElementType = getDerived().TransformType(T->getElementType());
4454 if (ElementType.isNull())
4455 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004456
Richard Smith764d2fe2011-12-20 02:08:33 +00004457 // Vector sizes are constant expressions.
4458 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4459 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004460
John McCalldadc5752010-08-24 06:29:42 +00004461 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004462 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004463 if (Size.isInvalid())
4464 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004465
John McCall550e0c22009-10-21 00:40:46 +00004466 QualType Result = TL.getType();
4467 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004468 ElementType != T->getElementType() ||
4469 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004470 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004471 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004473 if (Result.isNull())
4474 return QualType();
4475 }
John McCall550e0c22009-10-21 00:40:46 +00004476
4477 // Result might be dependent or not.
4478 if (isa<DependentSizedExtVectorType>(Result)) {
4479 DependentSizedExtVectorTypeLoc NewTL
4480 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4481 NewTL.setNameLoc(TL.getNameLoc());
4482 } else {
4483 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4484 NewTL.setNameLoc(TL.getNameLoc());
4485 }
4486
4487 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004488}
Mike Stump11289f42009-09-09 15:08:12 +00004489
4490template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004491QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004492 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004493 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494 QualType ElementType = getDerived().TransformType(T->getElementType());
4495 if (ElementType.isNull())
4496 return QualType();
4497
John McCall550e0c22009-10-21 00:40:46 +00004498 QualType Result = TL.getType();
4499 if (getDerived().AlwaysRebuild() ||
4500 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004501 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004502 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004503 if (Result.isNull())
4504 return QualType();
4505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004506
John McCall550e0c22009-10-21 00:40:46 +00004507 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4508 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004509
John McCall550e0c22009-10-21 00:40:46 +00004510 return Result;
4511}
4512
4513template<typename Derived>
4514QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004515 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004516 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004517 QualType ElementType = getDerived().TransformType(T->getElementType());
4518 if (ElementType.isNull())
4519 return QualType();
4520
4521 QualType Result = TL.getType();
4522 if (getDerived().AlwaysRebuild() ||
4523 ElementType != T->getElementType()) {
4524 Result = getDerived().RebuildExtVectorType(ElementType,
4525 T->getNumElements(),
4526 /*FIXME*/ SourceLocation());
4527 if (Result.isNull())
4528 return QualType();
4529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004530
John McCall550e0c22009-10-21 00:40:46 +00004531 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4532 NewTL.setNameLoc(TL.getNameLoc());
4533
4534 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
David Blaikie05785d12013-02-20 22:23:23 +00004537template <typename Derived>
4538ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4539 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4540 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004541 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004542 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004543
Douglas Gregor715e4612011-01-14 22:40:04 +00004544 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004545 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004546 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004547 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004548 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004549
Douglas Gregor715e4612011-01-14 22:40:04 +00004550 TypeLocBuilder TLB;
4551 TypeLoc NewTL = OldDI->getTypeLoc();
4552 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004553
4554 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004555 OldExpansionTL.getPatternLoc());
4556 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004557 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
4559 Result = RebuildPackExpansionType(Result,
4560 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004561 OldExpansionTL.getEllipsisLoc(),
4562 NumExpansions);
4563 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004564 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004565
Douglas Gregor715e4612011-01-14 22:40:04 +00004566 PackExpansionTypeLoc NewExpansionTL
4567 = TLB.push<PackExpansionTypeLoc>(Result);
4568 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4569 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4570 } else
4571 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004572 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004573 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004574
John McCall8fb0d9d2011-05-01 22:35:37 +00004575 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004576 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004577
4578 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4579 OldParm->getDeclContext(),
4580 OldParm->getInnerLocStart(),
4581 OldParm->getLocation(),
4582 OldParm->getIdentifier(),
4583 NewDI->getType(),
4584 NewDI,
4585 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004586 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004587 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4588 OldParm->getFunctionScopeIndex() + indexAdjustment);
4589 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004590}
4591
4592template<typename Derived>
4593bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004594 TransformFunctionTypeParams(SourceLocation Loc,
4595 ParmVarDecl **Params, unsigned NumParams,
4596 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004597 SmallVectorImpl<QualType> &OutParamTypes,
4598 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004599 int indexAdjustment = 0;
4600
Douglas Gregordd472162011-01-07 00:20:55 +00004601 for (unsigned i = 0; i != NumParams; ++i) {
4602 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004603 assert(OldParm->getFunctionScopeIndex() == i);
4604
David Blaikie05785d12013-02-20 22:23:23 +00004605 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004606 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004607 if (OldParm->isParameterPack()) {
4608 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004609 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004610
Douglas Gregor5499af42011-01-05 23:12:31 +00004611 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004612 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004613 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004614 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4615 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004616 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4617
Douglas Gregor5499af42011-01-05 23:12:31 +00004618 // Determine whether we should expand the parameter packs.
4619 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004620 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004621 Optional<unsigned> OrigNumExpansions =
4622 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004623 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004624 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4625 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004626 Unexpanded,
4627 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004628 RetainExpansion,
4629 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004630 return true;
4631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Douglas Gregor5499af42011-01-05 23:12:31 +00004633 if (ShouldExpand) {
4634 // Expand the function parameter pack into multiple, separate
4635 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004636 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004637 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004638 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004639 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004640 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004641 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004642 OrigNumExpansions,
4643 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004644 if (!NewParm)
4645 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004646
Douglas Gregordd472162011-01-07 00:20:55 +00004647 OutParamTypes.push_back(NewParm->getType());
4648 if (PVars)
4649 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004650 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004651
4652 // If we're supposed to retain a pack expansion, do so by temporarily
4653 // forgetting the partially-substituted parameter pack.
4654 if (RetainExpansion) {
4655 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004656 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004657 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004658 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004659 OrigNumExpansions,
4660 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004661 if (!NewParm)
4662 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004663
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004664 OutParamTypes.push_back(NewParm->getType());
4665 if (PVars)
4666 PVars->push_back(NewParm);
4667 }
4668
John McCall8fb0d9d2011-05-01 22:35:37 +00004669 // The next parameter should have the same adjustment as the
4670 // last thing we pushed, but we post-incremented indexAdjustment
4671 // on every push. Also, if we push nothing, the adjustment should
4672 // go down by one.
4673 indexAdjustment--;
4674
Douglas Gregor5499af42011-01-05 23:12:31 +00004675 // We're done with the pack expansion.
4676 continue;
4677 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004678
4679 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004680 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004681 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4682 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004683 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004684 NumExpansions,
4685 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004686 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004687 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004688 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004689 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004690
John McCall58f10c32010-03-11 09:03:00 +00004691 if (!NewParm)
4692 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004693
Douglas Gregordd472162011-01-07 00:20:55 +00004694 OutParamTypes.push_back(NewParm->getType());
4695 if (PVars)
4696 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004697 continue;
4698 }
John McCall58f10c32010-03-11 09:03:00 +00004699
4700 // Deal with the possibility that we don't have a parameter
4701 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004702 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004703 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004704 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004705 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004706 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004707 = dyn_cast<PackExpansionType>(OldType)) {
4708 // We have a function parameter pack that may need to be expanded.
4709 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004710 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004711 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004712
Douglas Gregor5499af42011-01-05 23:12:31 +00004713 // Determine whether we should expand the parameter packs.
4714 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004715 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004716 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004717 Unexpanded,
4718 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004719 RetainExpansion,
4720 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004721 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004723
Douglas Gregor5499af42011-01-05 23:12:31 +00004724 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004725 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004726 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004727 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004728 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4729 QualType NewType = getDerived().TransformType(Pattern);
4730 if (NewType.isNull())
4731 return true;
John McCall58f10c32010-03-11 09:03:00 +00004732
Douglas Gregordd472162011-01-07 00:20:55 +00004733 OutParamTypes.push_back(NewType);
4734 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004735 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004737
Douglas Gregor5499af42011-01-05 23:12:31 +00004738 // We're done with the pack expansion.
4739 continue;
4740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004741
Douglas Gregor48d24112011-01-10 20:53:55 +00004742 // If we're supposed to retain a pack expansion, do so by temporarily
4743 // forgetting the partially-substituted parameter pack.
4744 if (RetainExpansion) {
4745 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4746 QualType NewType = getDerived().TransformType(Pattern);
4747 if (NewType.isNull())
4748 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004749
Douglas Gregor48d24112011-01-10 20:53:55 +00004750 OutParamTypes.push_back(NewType);
4751 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004752 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004753 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004754
Chad Rosier1dcde962012-08-08 18:46:20 +00004755 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004756 // expansion.
4757 OldType = Expansion->getPattern();
4758 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004759 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4760 NewType = getDerived().TransformType(OldType);
4761 } else {
4762 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004764
Douglas Gregor5499af42011-01-05 23:12:31 +00004765 if (NewType.isNull())
4766 return true;
4767
4768 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004769 NewType = getSema().Context.getPackExpansionType(NewType,
4770 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004771
Douglas Gregordd472162011-01-07 00:20:55 +00004772 OutParamTypes.push_back(NewType);
4773 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004774 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004775 }
4776
John McCall8fb0d9d2011-05-01 22:35:37 +00004777#ifndef NDEBUG
4778 if (PVars) {
4779 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4780 if (ParmVarDecl *parm = (*PVars)[i])
4781 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004782 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004783#endif
4784
4785 return false;
4786}
John McCall58f10c32010-03-11 09:03:00 +00004787
4788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004789QualType
John McCall550e0c22009-10-21 00:40:46 +00004790TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004791 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004792 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004793 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004794 return getDerived().TransformFunctionProtoType(
4795 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004796 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4797 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4798 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004799 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004800}
4801
Richard Smith2e321552014-11-12 02:00:47 +00004802template<typename Derived> template<typename Fn>
4803QualType TreeTransform<Derived>::TransformFunctionProtoType(
4804 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4805 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004806 // Transform the parameters and return type.
4807 //
Richard Smithf623c962012-04-17 00:58:00 +00004808 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004809 // When the function has a trailing return type, we instantiate the
4810 // parameters before the return type, since the return type can then refer
4811 // to the parameters themselves (via decltype, sizeof, etc.).
4812 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004813 SmallVector<QualType, 4> ParamTypes;
4814 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004815 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004816
Douglas Gregor7fb25412010-10-01 18:44:50 +00004817 QualType ResultType;
4818
Richard Smith1226c602012-08-14 22:51:13 +00004819 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004820 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004821 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004822 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004823 return QualType();
4824
Douglas Gregor3024f072012-04-16 07:05:22 +00004825 {
4826 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004827 // If a declaration declares a member function or member function
4828 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004829 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004830 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004831 // declarator.
4832 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004833
Alp Toker42a16a62014-01-25 23:51:36 +00004834 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004835 if (ResultType.isNull())
4836 return QualType();
4837 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004838 }
4839 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004840 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004841 if (ResultType.isNull())
4842 return QualType();
4843
Alp Toker9cacbab2014-01-20 20:26:09 +00004844 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004845 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004846 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004847 return QualType();
4848 }
4849
Richard Smith2e321552014-11-12 02:00:47 +00004850 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4851
4852 bool EPIChanged = false;
4853 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4854 return QualType();
4855
4856 // FIXME: Need to transform ConsumedParameters for variadic template
4857 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004858
John McCall550e0c22009-10-21 00:40:46 +00004859 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004860 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004861 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004862 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004863 if (Result.isNull())
4864 return QualType();
4865 }
Mike Stump11289f42009-09-09 15:08:12 +00004866
John McCall550e0c22009-10-21 00:40:46 +00004867 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004868 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004869 NewTL.setLParenLoc(TL.getLParenLoc());
4870 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004871 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004872 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4873 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004874
4875 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876}
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004879bool TreeTransform<Derived>::TransformExceptionSpec(
4880 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4881 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4882 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4883
4884 // Instantiate a dynamic noexcept expression, if any.
4885 if (ESI.Type == EST_ComputedNoexcept) {
4886 EnterExpressionEvaluationContext Unevaluated(getSema(),
4887 Sema::ConstantEvaluated);
4888 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4889 if (NoexceptExpr.isInvalid())
4890 return true;
4891
4892 NoexceptExpr = getSema().CheckBooleanCondition(
4893 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4894 if (NoexceptExpr.isInvalid())
4895 return true;
4896
4897 if (!NoexceptExpr.get()->isValueDependent()) {
4898 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4899 NoexceptExpr.get(), nullptr,
4900 diag::err_noexcept_needs_constant_expression,
4901 /*AllowFold*/false);
4902 if (NoexceptExpr.isInvalid())
4903 return true;
4904 }
4905
4906 if (ESI.NoexceptExpr != NoexceptExpr.get())
4907 Changed = true;
4908 ESI.NoexceptExpr = NoexceptExpr.get();
4909 }
4910
4911 if (ESI.Type != EST_Dynamic)
4912 return false;
4913
4914 // Instantiate a dynamic exception specification's type.
4915 for (QualType T : ESI.Exceptions) {
4916 if (const PackExpansionType *PackExpansion =
4917 T->getAs<PackExpansionType>()) {
4918 Changed = true;
4919
4920 // We have a pack expansion. Instantiate it.
4921 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4922 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4923 Unexpanded);
4924 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4925
4926 // Determine whether the set of unexpanded parameter packs can and
4927 // should
4928 // be expanded.
4929 bool Expand = false;
4930 bool RetainExpansion = false;
4931 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4932 // FIXME: Track the location of the ellipsis (and track source location
4933 // information for the types in the exception specification in general).
4934 if (getDerived().TryExpandParameterPacks(
4935 Loc, SourceRange(), Unexpanded, Expand,
4936 RetainExpansion, NumExpansions))
4937 return true;
4938
4939 if (!Expand) {
4940 // We can't expand this pack expansion into separate arguments yet;
4941 // just substitute into the pattern and create a new pack expansion
4942 // type.
4943 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4944 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4945 if (U.isNull())
4946 return true;
4947
4948 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4949 Exceptions.push_back(U);
4950 continue;
4951 }
4952
4953 // Substitute into the pack expansion pattern for each slice of the
4954 // pack.
4955 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4956 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4957
4958 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4959 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4960 return true;
4961
4962 Exceptions.push_back(U);
4963 }
4964 } else {
4965 QualType U = getDerived().TransformType(T);
4966 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4967 return true;
4968 if (T != U)
4969 Changed = true;
4970
4971 Exceptions.push_back(U);
4972 }
4973 }
4974
4975 ESI.Exceptions = Exceptions;
4976 return false;
4977}
4978
4979template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004981 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004982 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004983 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004984 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004985 if (ResultType.isNull())
4986 return QualType();
4987
4988 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004989 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004990 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4991
4992 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004993 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004994 NewTL.setLParenLoc(TL.getLParenLoc());
4995 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004996 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004997
4998 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004999}
Mike Stump11289f42009-09-09 15:08:12 +00005000
John McCallb96ec562009-12-04 22:46:56 +00005001template<typename Derived> QualType
5002TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005003 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005004 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005005 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005006 if (!D)
5007 return QualType();
5008
5009 QualType Result = TL.getType();
5010 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5011 Result = getDerived().RebuildUnresolvedUsingType(D);
5012 if (Result.isNull())
5013 return QualType();
5014 }
5015
5016 // We might get an arbitrary type spec type back. We should at
5017 // least always get a type spec type, though.
5018 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5019 NewTL.setNameLoc(TL.getNameLoc());
5020
5021 return Result;
5022}
5023
Douglas Gregord6ff3322009-08-04 16:50:30 +00005024template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005025QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005026 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005027 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005028 TypedefNameDecl *Typedef
5029 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5030 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005031 if (!Typedef)
5032 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005033
John McCall550e0c22009-10-21 00:40:46 +00005034 QualType Result = TL.getType();
5035 if (getDerived().AlwaysRebuild() ||
5036 Typedef != T->getDecl()) {
5037 Result = getDerived().RebuildTypedefType(Typedef);
5038 if (Result.isNull())
5039 return QualType();
5040 }
Mike Stump11289f42009-09-09 15:08:12 +00005041
John McCall550e0c22009-10-21 00:40:46 +00005042 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5043 NewTL.setNameLoc(TL.getNameLoc());
5044
5045 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregord6ff3322009-08-04 16:50:30 +00005048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005049QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005050 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005051 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5053 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005054
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005056 if (E.isInvalid())
5057 return QualType();
5058
Eli Friedmane4f22df2012-02-29 04:03:55 +00005059 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5060 if (E.isInvalid())
5061 return QualType();
5062
John McCall550e0c22009-10-21 00:40:46 +00005063 QualType Result = TL.getType();
5064 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005065 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005066 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005067 if (Result.isNull())
5068 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005069 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005070 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005071
John McCall550e0c22009-10-21 00:40:46 +00005072 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005073 NewTL.setTypeofLoc(TL.getTypeofLoc());
5074 NewTL.setLParenLoc(TL.getLParenLoc());
5075 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005076
5077 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005078}
Mike Stump11289f42009-09-09 15:08:12 +00005079
5080template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005081QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005082 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005083 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5084 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5085 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005087
John McCall550e0c22009-10-21 00:40:46 +00005088 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005089 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5090 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005091 if (Result.isNull())
5092 return QualType();
5093 }
Mike Stump11289f42009-09-09 15:08:12 +00005094
John McCall550e0c22009-10-21 00:40:46 +00005095 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005096 NewTL.setTypeofLoc(TL.getTypeofLoc());
5097 NewTL.setLParenLoc(TL.getLParenLoc());
5098 NewTL.setRParenLoc(TL.getRParenLoc());
5099 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005100
5101 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005102}
Mike Stump11289f42009-09-09 15:08:12 +00005103
5104template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005105QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005106 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005107 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005108
Douglas Gregore922c772009-08-04 22:27:00 +00005109 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005110 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5111 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005112
John McCalldadc5752010-08-24 06:29:42 +00005113 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005114 if (E.isInvalid())
5115 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005116
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005117 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005118 if (E.isInvalid())
5119 return QualType();
5120
John McCall550e0c22009-10-21 00:40:46 +00005121 QualType Result = TL.getType();
5122 if (getDerived().AlwaysRebuild() ||
5123 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005124 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005125 if (Result.isNull())
5126 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005128 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005129
John McCall550e0c22009-10-21 00:40:46 +00005130 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5131 NewTL.setNameLoc(TL.getNameLoc());
5132
5133 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005134}
5135
5136template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005137QualType TreeTransform<Derived>::TransformUnaryTransformType(
5138 TypeLocBuilder &TLB,
5139 UnaryTransformTypeLoc TL) {
5140 QualType Result = TL.getType();
5141 if (Result->isDependentType()) {
5142 const UnaryTransformType *T = TL.getTypePtr();
5143 QualType NewBase =
5144 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5145 Result = getDerived().RebuildUnaryTransformType(NewBase,
5146 T->getUTTKind(),
5147 TL.getKWLoc());
5148 if (Result.isNull())
5149 return QualType();
5150 }
5151
5152 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5153 NewTL.setKWLoc(TL.getKWLoc());
5154 NewTL.setParensRange(TL.getParensRange());
5155 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5156 return Result;
5157}
5158
5159template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005160QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5161 AutoTypeLoc TL) {
5162 const AutoType *T = TL.getTypePtr();
5163 QualType OldDeduced = T->getDeducedType();
5164 QualType NewDeduced;
5165 if (!OldDeduced.isNull()) {
5166 NewDeduced = getDerived().TransformType(OldDeduced);
5167 if (NewDeduced.isNull())
5168 return QualType();
5169 }
5170
5171 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005172 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5173 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005174 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005175 if (Result.isNull())
5176 return QualType();
5177 }
5178
5179 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5180 NewTL.setNameLoc(TL.getNameLoc());
5181
5182 return Result;
5183}
5184
5185template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005186QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005187 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005188 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005189 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005190 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5191 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005192 if (!Record)
5193 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005194
John McCall550e0c22009-10-21 00:40:46 +00005195 QualType Result = TL.getType();
5196 if (getDerived().AlwaysRebuild() ||
5197 Record != T->getDecl()) {
5198 Result = getDerived().RebuildRecordType(Record);
5199 if (Result.isNull())
5200 return QualType();
5201 }
Mike Stump11289f42009-09-09 15:08:12 +00005202
John McCall550e0c22009-10-21 00:40:46 +00005203 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5204 NewTL.setNameLoc(TL.getNameLoc());
5205
5206 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
5209template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005210QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005211 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005212 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005213 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005214 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5215 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005216 if (!Enum)
5217 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005218
John McCall550e0c22009-10-21 00:40:46 +00005219 QualType Result = TL.getType();
5220 if (getDerived().AlwaysRebuild() ||
5221 Enum != T->getDecl()) {
5222 Result = getDerived().RebuildEnumType(Enum);
5223 if (Result.isNull())
5224 return QualType();
5225 }
Mike Stump11289f42009-09-09 15:08:12 +00005226
John McCall550e0c22009-10-21 00:40:46 +00005227 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5228 NewTL.setNameLoc(TL.getNameLoc());
5229
5230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231}
John McCallfcc33b02009-09-05 00:15:47 +00005232
John McCalle78aac42010-03-10 03:28:59 +00005233template<typename Derived>
5234QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5235 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005236 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005237 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5238 TL.getTypePtr()->getDecl());
5239 if (!D) return QualType();
5240
5241 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5242 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5243 return T;
5244}
5245
Douglas Gregord6ff3322009-08-04 16:50:30 +00005246template<typename Derived>
5247QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005248 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005249 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005250 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251}
5252
Mike Stump11289f42009-09-09 15:08:12 +00005253template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005254QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005255 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005256 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005257 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005258
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005259 // Substitute into the replacement type, which itself might involve something
5260 // that needs to be transformed. This only tends to occur with default
5261 // template arguments of template template parameters.
5262 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5263 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5264 if (Replacement.isNull())
5265 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005266
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005267 // Always canonicalize the replacement type.
5268 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5269 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005270 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005271 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005273 // Propagate type-source information.
5274 SubstTemplateTypeParmTypeLoc NewTL
5275 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5276 NewTL.setNameLoc(TL.getNameLoc());
5277 return Result;
5278
John McCallcebee162009-10-18 09:09:24 +00005279}
5280
5281template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005282QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5283 TypeLocBuilder &TLB,
5284 SubstTemplateTypeParmPackTypeLoc TL) {
5285 return TransformTypeSpecType(TLB, TL);
5286}
5287
5288template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005289QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005290 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005291 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005292 const TemplateSpecializationType *T = TL.getTypePtr();
5293
Douglas Gregordf846d12011-03-02 18:46:51 +00005294 // The nested-name-specifier never matters in a TemplateSpecializationType,
5295 // because we can't have a dependent nested-name-specifier anyway.
5296 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005297 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005298 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5299 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005300 if (Template.isNull())
5301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005302
John McCall31f82722010-11-12 08:19:04 +00005303 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5304}
5305
Eli Friedman0dfb8892011-10-06 23:00:33 +00005306template<typename Derived>
5307QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5308 AtomicTypeLoc TL) {
5309 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5310 if (ValueType.isNull())
5311 return QualType();
5312
5313 QualType Result = TL.getType();
5314 if (getDerived().AlwaysRebuild() ||
5315 ValueType != TL.getValueLoc().getType()) {
5316 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5317 if (Result.isNull())
5318 return QualType();
5319 }
5320
5321 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5322 NewTL.setKWLoc(TL.getKWLoc());
5323 NewTL.setLParenLoc(TL.getLParenLoc());
5324 NewTL.setRParenLoc(TL.getRParenLoc());
5325
5326 return Result;
5327}
5328
Chad Rosier1dcde962012-08-08 18:46:20 +00005329 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005330 /// container that provides a \c getArgLoc() member function.
5331 ///
5332 /// This iterator is intended to be used with the iterator form of
5333 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5334 template<typename ArgLocContainer>
5335 class TemplateArgumentLocContainerIterator {
5336 ArgLocContainer *Container;
5337 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005338
Douglas Gregorfe921a72010-12-20 23:36:19 +00005339 public:
5340 typedef TemplateArgumentLoc value_type;
5341 typedef TemplateArgumentLoc reference;
5342 typedef int difference_type;
5343 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005344
Douglas Gregorfe921a72010-12-20 23:36:19 +00005345 class pointer {
5346 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
Douglas Gregorfe921a72010-12-20 23:36:19 +00005348 public:
5349 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005350
Douglas Gregorfe921a72010-12-20 23:36:19 +00005351 const TemplateArgumentLoc *operator->() const {
5352 return &Arg;
5353 }
5354 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005355
5356
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005357 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005358
Douglas Gregorfe921a72010-12-20 23:36:19 +00005359 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5360 unsigned Index)
5361 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005362
Douglas Gregorfe921a72010-12-20 23:36:19 +00005363 TemplateArgumentLocContainerIterator &operator++() {
5364 ++Index;
5365 return *this;
5366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005367
Douglas Gregorfe921a72010-12-20 23:36:19 +00005368 TemplateArgumentLocContainerIterator operator++(int) {
5369 TemplateArgumentLocContainerIterator Old(*this);
5370 ++(*this);
5371 return Old;
5372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005373
Douglas Gregorfe921a72010-12-20 23:36:19 +00005374 TemplateArgumentLoc operator*() const {
5375 return Container->getArgLoc(Index);
5376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005377
Douglas Gregorfe921a72010-12-20 23:36:19 +00005378 pointer operator->() const {
5379 return pointer(Container->getArgLoc(Index));
5380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005381
Douglas Gregorfe921a72010-12-20 23:36:19 +00005382 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005383 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005384 return X.Container == Y.Container && X.Index == Y.Index;
5385 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005386
Douglas Gregorfe921a72010-12-20 23:36:19 +00005387 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005388 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005389 return !(X == Y);
5390 }
5391 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005392
5393
John McCall31f82722010-11-12 08:19:04 +00005394template <typename Derived>
5395QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5396 TypeLocBuilder &TLB,
5397 TemplateSpecializationTypeLoc TL,
5398 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005399 TemplateArgumentListInfo NewTemplateArgs;
5400 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5401 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005402 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5403 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005404 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005405 ArgIterator(TL, TL.getNumArgs()),
5406 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005407 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005408
John McCall0ad16662009-10-29 08:12:44 +00005409 // FIXME: maybe don't rebuild if all the template arguments are the same.
5410
5411 QualType Result =
5412 getDerived().RebuildTemplateSpecializationType(Template,
5413 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005414 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005415
5416 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005417 // Specializations of template template parameters are represented as
5418 // TemplateSpecializationTypes, and substitution of type alias templates
5419 // within a dependent context can transform them into
5420 // DependentTemplateSpecializationTypes.
5421 if (isa<DependentTemplateSpecializationType>(Result)) {
5422 DependentTemplateSpecializationTypeLoc NewTL
5423 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005424 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005425 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005426 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005427 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005428 NewTL.setLAngleLoc(TL.getLAngleLoc());
5429 NewTL.setRAngleLoc(TL.getRAngleLoc());
5430 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5431 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5432 return Result;
5433 }
5434
John McCall0ad16662009-10-29 08:12:44 +00005435 TemplateSpecializationTypeLoc NewTL
5436 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005437 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005438 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5439 NewTL.setLAngleLoc(TL.getLAngleLoc());
5440 NewTL.setRAngleLoc(TL.getRAngleLoc());
5441 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5442 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443 }
Mike Stump11289f42009-09-09 15:08:12 +00005444
John McCall0ad16662009-10-29 08:12:44 +00005445 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregor5a064722011-02-28 17:23:35 +00005448template <typename Derived>
5449QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5450 TypeLocBuilder &TLB,
5451 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005452 TemplateName Template,
5453 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005454 TemplateArgumentListInfo NewTemplateArgs;
5455 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5456 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5457 typedef TemplateArgumentLocContainerIterator<
5458 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005459 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005460 ArgIterator(TL, TL.getNumArgs()),
5461 NewTemplateArgs))
5462 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005463
Douglas Gregor5a064722011-02-28 17:23:35 +00005464 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005465
Douglas Gregor5a064722011-02-28 17:23:35 +00005466 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5467 QualType Result
5468 = getSema().Context.getDependentTemplateSpecializationType(
5469 TL.getTypePtr()->getKeyword(),
5470 DTN->getQualifier(),
5471 DTN->getIdentifier(),
5472 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005473
Douglas Gregor5a064722011-02-28 17:23:35 +00005474 DependentTemplateSpecializationTypeLoc NewTL
5475 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005476 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005477 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005478 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005479 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005480 NewTL.setLAngleLoc(TL.getLAngleLoc());
5481 NewTL.setRAngleLoc(TL.getRAngleLoc());
5482 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5483 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5484 return Result;
5485 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005486
5487 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005488 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005489 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005490 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005491
Douglas Gregor5a064722011-02-28 17:23:35 +00005492 if (!Result.isNull()) {
5493 /// FIXME: Wrap this in an elaborated-type-specifier?
5494 TemplateSpecializationTypeLoc NewTL
5495 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005496 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005497 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005498 NewTL.setLAngleLoc(TL.getLAngleLoc());
5499 NewTL.setRAngleLoc(TL.getRAngleLoc());
5500 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5501 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5502 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005503
Douglas Gregor5a064722011-02-28 17:23:35 +00005504 return Result;
5505}
5506
Mike Stump11289f42009-09-09 15:08:12 +00005507template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005508QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005509TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005510 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005511 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005512
Douglas Gregor844cb502011-03-01 18:12:44 +00005513 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005514 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005515 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005516 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005517 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5518 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005519 return QualType();
5520 }
Mike Stump11289f42009-09-09 15:08:12 +00005521
John McCall31f82722010-11-12 08:19:04 +00005522 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5523 if (NamedT.isNull())
5524 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005525
Richard Smith3f1b5d02011-05-05 21:57:07 +00005526 // C++0x [dcl.type.elab]p2:
5527 // If the identifier resolves to a typedef-name or the simple-template-id
5528 // resolves to an alias template specialization, the
5529 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005530 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5531 if (const TemplateSpecializationType *TST =
5532 NamedT->getAs<TemplateSpecializationType>()) {
5533 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005534 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5535 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005536 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5537 diag::err_tag_reference_non_tag) << 4;
5538 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5539 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005540 }
5541 }
5542
John McCall550e0c22009-10-21 00:40:46 +00005543 QualType Result = TL.getType();
5544 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005545 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005546 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005547 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005548 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005549 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005550 if (Result.isNull())
5551 return QualType();
5552 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005553
Abramo Bagnara6150c882010-05-11 21:36:43 +00005554 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005555 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005556 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005557 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
5560template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005561QualType TreeTransform<Derived>::TransformAttributedType(
5562 TypeLocBuilder &TLB,
5563 AttributedTypeLoc TL) {
5564 const AttributedType *oldType = TL.getTypePtr();
5565 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5566 if (modifiedType.isNull())
5567 return QualType();
5568
5569 QualType result = TL.getType();
5570
5571 // FIXME: dependent operand expressions?
5572 if (getDerived().AlwaysRebuild() ||
5573 modifiedType != oldType->getModifiedType()) {
5574 // TODO: this is really lame; we should really be rebuilding the
5575 // equivalent type from first principles.
5576 QualType equivalentType
5577 = getDerived().TransformType(oldType->getEquivalentType());
5578 if (equivalentType.isNull())
5579 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005580
5581 // Check whether we can add nullability; it is only represented as
5582 // type sugar, and therefore cannot be diagnosed in any other way.
5583 if (auto nullability = oldType->getImmediateNullability()) {
5584 if (!modifiedType->canHaveNullability()) {
5585 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005586 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005587 return QualType();
5588 }
5589 }
5590
John McCall81904512011-01-06 01:58:22 +00005591 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5592 modifiedType,
5593 equivalentType);
5594 }
5595
5596 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5597 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5598 if (TL.hasAttrOperand())
5599 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5600 if (TL.hasAttrExprOperand())
5601 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5602 else if (TL.hasAttrEnumOperand())
5603 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5604
5605 return result;
5606}
5607
5608template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005609QualType
5610TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5611 ParenTypeLoc TL) {
5612 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5613 if (Inner.isNull())
5614 return QualType();
5615
5616 QualType Result = TL.getType();
5617 if (getDerived().AlwaysRebuild() ||
5618 Inner != TL.getInnerLoc().getType()) {
5619 Result = getDerived().RebuildParenType(Inner);
5620 if (Result.isNull())
5621 return QualType();
5622 }
5623
5624 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5625 NewTL.setLParenLoc(TL.getLParenLoc());
5626 NewTL.setRParenLoc(TL.getRParenLoc());
5627 return Result;
5628}
5629
5630template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005631QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005632 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005633 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005634
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005635 NestedNameSpecifierLoc QualifierLoc
5636 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5637 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005638 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005639
John McCallc392f372010-06-11 00:33:02 +00005640 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005641 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005642 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005643 QualifierLoc,
5644 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005645 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005646 if (Result.isNull())
5647 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005648
Abramo Bagnarad7548482010-05-19 21:37:53 +00005649 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5650 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005651 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5652
Abramo Bagnarad7548482010-05-19 21:37:53 +00005653 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005654 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005655 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005656 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005657 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005658 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005659 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005660 NewTL.setNameLoc(TL.getNameLoc());
5661 }
John McCall550e0c22009-10-21 00:40:46 +00005662 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregord6ff3322009-08-04 16:50:30 +00005665template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005666QualType TreeTransform<Derived>::
5667 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005668 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005669 NestedNameSpecifierLoc QualifierLoc;
5670 if (TL.getQualifierLoc()) {
5671 QualifierLoc
5672 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5673 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005674 return QualType();
5675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005676
John McCall31f82722010-11-12 08:19:04 +00005677 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005678 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005679}
5680
5681template<typename Derived>
5682QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005683TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5684 DependentTemplateSpecializationTypeLoc TL,
5685 NestedNameSpecifierLoc QualifierLoc) {
5686 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005687
Douglas Gregora7a795b2011-03-01 20:11:18 +00005688 TemplateArgumentListInfo NewTemplateArgs;
5689 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5690 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005691
Douglas Gregora7a795b2011-03-01 20:11:18 +00005692 typedef TemplateArgumentLocContainerIterator<
5693 DependentTemplateSpecializationTypeLoc> ArgIterator;
5694 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5695 ArgIterator(TL, TL.getNumArgs()),
5696 NewTemplateArgs))
5697 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005698
Douglas Gregora7a795b2011-03-01 20:11:18 +00005699 QualType Result
5700 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5701 QualifierLoc,
5702 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005703 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005704 NewTemplateArgs);
5705 if (Result.isNull())
5706 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Douglas Gregora7a795b2011-03-01 20:11:18 +00005708 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5709 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
Douglas Gregora7a795b2011-03-01 20:11:18 +00005711 // Copy information relevant to the template specialization.
5712 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005713 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005714 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005715 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005716 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5717 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005718 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005719 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005720
Douglas Gregora7a795b2011-03-01 20:11:18 +00005721 // Copy information relevant to the elaborated type.
5722 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005723 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005724 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005725 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5726 DependentTemplateSpecializationTypeLoc SpecTL
5727 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005728 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005729 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005730 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005731 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005732 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5733 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005734 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005735 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005736 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005737 TemplateSpecializationTypeLoc SpecTL
5738 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005739 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005740 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005741 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5742 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005743 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005744 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005745 }
5746 return Result;
5747}
5748
5749template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005750QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5751 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005752 QualType Pattern
5753 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005754 if (Pattern.isNull())
5755 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
5757 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005758 if (getDerived().AlwaysRebuild() ||
5759 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005760 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005761 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005762 TL.getEllipsisLoc(),
5763 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005764 if (Result.isNull())
5765 return QualType();
5766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005767
Douglas Gregor822d0302011-01-12 17:07:58 +00005768 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5769 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5770 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005771}
5772
5773template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005774QualType
5775TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005776 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005777 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005778 TLB.pushFullCopy(TL);
5779 return TL.getType();
5780}
5781
5782template<typename Derived>
5783QualType
5784TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005785 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005786 // Transform base type.
5787 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5788 if (BaseType.isNull())
5789 return QualType();
5790
5791 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5792
5793 // Transform type arguments.
5794 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5795 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5796 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5797 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5798 QualType TypeArg = TypeArgInfo->getType();
5799 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5800 AnyChanged = true;
5801
5802 // We have a pack expansion. Instantiate it.
5803 const auto *PackExpansion = PackExpansionLoc.getType()
5804 ->castAs<PackExpansionType>();
5805 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5806 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5807 Unexpanded);
5808 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5809
5810 // Determine whether the set of unexpanded parameter packs can
5811 // and should be expanded.
5812 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5813 bool Expand = false;
5814 bool RetainExpansion = false;
5815 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5816 if (getDerived().TryExpandParameterPacks(
5817 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5818 Unexpanded, Expand, RetainExpansion, NumExpansions))
5819 return QualType();
5820
5821 if (!Expand) {
5822 // We can't expand this pack expansion into separate arguments yet;
5823 // just substitute into the pattern and create a new pack expansion
5824 // type.
5825 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5826
5827 TypeLocBuilder TypeArgBuilder;
5828 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5829 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5830 PatternLoc);
5831 if (NewPatternType.isNull())
5832 return QualType();
5833
5834 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5835 NewPatternType, NumExpansions);
5836 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5837 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5838 NewTypeArgInfos.push_back(
5839 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5840 continue;
5841 }
5842
5843 // Substitute into the pack expansion pattern for each slice of the
5844 // pack.
5845 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5846 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5847
5848 TypeLocBuilder TypeArgBuilder;
5849 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5850
5851 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5852 PatternLoc);
5853 if (NewTypeArg.isNull())
5854 return QualType();
5855
5856 NewTypeArgInfos.push_back(
5857 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5858 }
5859
5860 continue;
5861 }
5862
5863 TypeLocBuilder TypeArgBuilder;
5864 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5865 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5866 if (NewTypeArg.isNull())
5867 return QualType();
5868
5869 // If nothing changed, just keep the old TypeSourceInfo.
5870 if (NewTypeArg == TypeArg) {
5871 NewTypeArgInfos.push_back(TypeArgInfo);
5872 continue;
5873 }
5874
5875 NewTypeArgInfos.push_back(
5876 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5877 AnyChanged = true;
5878 }
5879
5880 QualType Result = TL.getType();
5881 if (getDerived().AlwaysRebuild() || AnyChanged) {
5882 // Rebuild the type.
5883 Result = getDerived().RebuildObjCObjectType(
5884 BaseType,
5885 TL.getLocStart(),
5886 TL.getTypeArgsLAngleLoc(),
5887 NewTypeArgInfos,
5888 TL.getTypeArgsRAngleLoc(),
5889 TL.getProtocolLAngleLoc(),
5890 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5891 TL.getNumProtocols()),
5892 TL.getProtocolLocs(),
5893 TL.getProtocolRAngleLoc());
5894
5895 if (Result.isNull())
5896 return QualType();
5897 }
5898
5899 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5900 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5901 NewT.setHasBaseTypeAsWritten(true);
5902 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5903 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5904 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5905 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5906 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5907 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5908 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5909 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5910 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005911}
Mike Stump11289f42009-09-09 15:08:12 +00005912
5913template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005914QualType
5915TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005916 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005917 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5918 if (PointeeType.isNull())
5919 return QualType();
5920
5921 QualType Result = TL.getType();
5922 if (getDerived().AlwaysRebuild() ||
5923 PointeeType != TL.getPointeeLoc().getType()) {
5924 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5925 TL.getStarLoc());
5926 if (Result.isNull())
5927 return QualType();
5928 }
5929
5930 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5931 NewT.setStarLoc(TL.getStarLoc());
5932 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005933}
5934
Douglas Gregord6ff3322009-08-04 16:50:30 +00005935//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005936// Statement transformation
5937//===----------------------------------------------------------------------===//
5938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005940TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005941 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005942}
5943
5944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005945StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005946TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5947 return getDerived().TransformCompoundStmt(S, false);
5948}
5949
5950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005951StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005952TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005953 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005954 Sema::CompoundScopeRAII CompoundScope(getSema());
5955
John McCall1ababa62010-08-27 19:56:05 +00005956 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005957 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005958 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005959 for (auto *B : S->body()) {
5960 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005961 if (Result.isInvalid()) {
5962 // Immediately fail if this was a DeclStmt, since it's very
5963 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005964 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005965 return StmtError();
5966
5967 // Otherwise, just keep processing substatements and fail later.
5968 SubStmtInvalid = true;
5969 continue;
5970 }
Mike Stump11289f42009-09-09 15:08:12 +00005971
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005972 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005973 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005974 }
Mike Stump11289f42009-09-09 15:08:12 +00005975
John McCall1ababa62010-08-27 19:56:05 +00005976 if (SubStmtInvalid)
5977 return StmtError();
5978
Douglas Gregorebe10102009-08-20 07:17:43 +00005979 if (!getDerived().AlwaysRebuild() &&
5980 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005981 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005982
5983 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005984 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005985 S->getRBracLoc(),
5986 IsStmtExpr);
5987}
Mike Stump11289f42009-09-09 15:08:12 +00005988
Douglas Gregorebe10102009-08-20 07:17:43 +00005989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005990StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005991TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005992 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005993 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005994 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5995 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005996
Eli Friedman06577382009-11-19 03:14:00 +00005997 // Transform the left-hand case value.
5998 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005999 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006000 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006002
Eli Friedman06577382009-11-19 03:14:00 +00006003 // Transform the right-hand case value (for the GNU case-range extension).
6004 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006005 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006006 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006008 }
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 // Build the case statement.
6011 // Case statements are always rebuilt so that they will attached to their
6012 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006013 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006014 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006016 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006017 S->getColonLoc());
6018 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006019 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006022 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006023 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006027 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006028}
6029
6030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006032TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006034 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006035 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregorebe10102009-08-20 07:17:43 +00006038 // Default statements are always rebuilt
6039 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006040 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006041}
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregorebe10102009-08-20 07:17:43 +00006043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006044StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006045TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006046 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006047 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006049
Chris Lattnercab02a62011-02-17 20:34:02 +00006050 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6051 S->getDecl());
6052 if (!LD)
6053 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006054
6055
Douglas Gregorebe10102009-08-20 07:17:43 +00006056 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006057 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006058 cast<LabelDecl>(LD), SourceLocation(),
6059 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006060}
Mike Stump11289f42009-09-09 15:08:12 +00006061
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006062template <typename Derived>
6063const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6064 if (!R)
6065 return R;
6066
6067 switch (R->getKind()) {
6068// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6069#define ATTR(X)
6070#define PRAGMA_SPELLING_ATTR(X) \
6071 case attr::X: \
6072 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6073#include "clang/Basic/AttrList.inc"
6074 default:
6075 return R;
6076 }
6077}
6078
6079template <typename Derived>
6080StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6081 bool AttrsChanged = false;
6082 SmallVector<const Attr *, 1> Attrs;
6083
6084 // Visit attributes and keep track if any are transformed.
6085 for (const auto *I : S->getAttrs()) {
6086 const Attr *R = getDerived().TransformAttr(I);
6087 AttrsChanged |= (I != R);
6088 Attrs.push_back(R);
6089 }
6090
Richard Smithc202b282012-04-14 00:33:13 +00006091 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6092 if (SubStmt.isInvalid())
6093 return StmtError();
6094
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006095 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006096 return S;
6097
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006098 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006099 SubStmt.get());
6100}
6101
6102template<typename Derived>
6103StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006104TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006105 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006106 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006107 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006108 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006109 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006110 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006111 getDerived().TransformDefinition(
6112 S->getConditionVariable()->getLocation(),
6113 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006114 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006115 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006116 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006117 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006118
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006119 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006122 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006123 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006124 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006125 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006126 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006128
John McCallb268a282010-08-23 23:25:46 +00006129 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006130 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006132
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006133 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006134 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006136
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006138 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorebe10102009-08-20 07:17:43 +00006142 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006143 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006146
Douglas Gregorebe10102009-08-20 07:17:43 +00006147 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006148 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006149 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006150 Then.get() == S->getThen() &&
6151 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006152 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006154 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006155 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006156 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006157}
6158
6159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006161TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006163 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006164 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006165 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006166 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006167 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006168 getDerived().TransformDefinition(
6169 S->getConditionVariable()->getLocation(),
6170 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006171 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006173 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006174 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006175
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006176 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006178 }
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregorebe10102009-08-20 07:17:43 +00006180 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006181 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006182 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006183 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006184 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006185 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006188 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006191
Douglas Gregorebe10102009-08-20 07:17:43 +00006192 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006193 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6194 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006195}
Mike Stump11289f42009-09-09 15:08:12 +00006196
Douglas Gregorebe10102009-08-20 07:17:43 +00006197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006199TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006200 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006201 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006202 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006203 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006204 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006205 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006206 getDerived().TransformDefinition(
6207 S->getConditionVariable()->getLocation(),
6208 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006209 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006211 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006212 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006214 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006215 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006216
6217 if (S->getCond()) {
6218 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006219 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6220 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006221 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006222 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006224 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006225 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006226 }
Mike Stump11289f42009-09-09 15:08:12 +00006227
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006228 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006229 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006231
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006233 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006234 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006235 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregorebe10102009-08-20 07:17:43 +00006237 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006238 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006239 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006240 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006241 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006242
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006243 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006244 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006245}
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregorebe10102009-08-20 07:17:43 +00006247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006248StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006249TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006251 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006252 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006253 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006254
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006255 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006256 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006257 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregorebe10102009-08-20 07:17:43 +00006260 if (!getDerived().AlwaysRebuild() &&
6261 Cond.get() == S->getCond() &&
6262 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006263 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006264
John McCallb268a282010-08-23 23:25:46 +00006265 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6266 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006267 S->getRParenLoc());
6268}
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006271StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006272TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006273 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006274 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006275 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006276 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregorebe10102009-08-20 07:17:43 +00006278 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006279 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006280 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006281 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006282 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006283 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006284 getDerived().TransformDefinition(
6285 S->getConditionVariable()->getLocation(),
6286 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006287 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006289 } else {
6290 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006291
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006292 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006293 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006294
6295 if (S->getCond()) {
6296 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006297 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6298 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006299 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006300 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006302
John McCallb268a282010-08-23 23:25:46 +00006303 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006304 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006305 }
Mike Stump11289f42009-09-09 15:08:12 +00006306
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006307 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006308 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006309 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006310
Douglas Gregorebe10102009-08-20 07:17:43 +00006311 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006312 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006313 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006314 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006315
Richard Smith945f8d32013-01-14 22:39:08 +00006316 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006317 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006318 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006319
Douglas Gregorebe10102009-08-20 07:17:43 +00006320 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006321 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006323 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006324
Douglas Gregorebe10102009-08-20 07:17:43 +00006325 if (!getDerived().AlwaysRebuild() &&
6326 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006327 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006328 Inc.get() == S->getInc() &&
6329 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006330 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006333 Init.get(), FullCond, ConditionVar,
6334 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006335}
6336
6337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006338StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006339TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006340 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6341 S->getLabel());
6342 if (!LD)
6343 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006344
Douglas Gregorebe10102009-08-20 07:17:43 +00006345 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006346 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006347 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006348}
6349
6350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006351StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006352TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006353 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006354 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006355 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006356 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregorebe10102009-08-20 07:17:43 +00006358 if (!getDerived().AlwaysRebuild() &&
6359 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006360 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006361
6362 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006363 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006364}
6365
6366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006367StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006368TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006369 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006370}
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006373StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006374TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006375 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006376}
Mike Stump11289f42009-09-09 15:08:12 +00006377
Douglas Gregorebe10102009-08-20 07:17:43 +00006378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006379StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006380TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006381 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6382 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006383 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006385
Mike Stump11289f42009-09-09 15:08:12 +00006386 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006388 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006389}
Mike Stump11289f42009-09-09 15:08:12 +00006390
Douglas Gregorebe10102009-08-20 07:17:43 +00006391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006392StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006393TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006395 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006396 for (auto *D : S->decls()) {
6397 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006398 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006399 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006400
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006401 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006402 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 Decls.push_back(Transformed);
6405 }
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregorebe10102009-08-20 07:17:43 +00006407 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006408 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006409
Rafael Espindolaab417692013-07-09 12:05:01 +00006410 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006411}
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregorebe10102009-08-20 07:17:43 +00006413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006414StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006415TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006416
Benjamin Kramerf0623432012-08-23 22:51:59 +00006417 SmallVector<Expr*, 8> Constraints;
6418 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006419 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006420
John McCalldadc5752010-08-24 06:29:42 +00006421 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006422 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006423
6424 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006425
Anders Carlssonaaeef072010-01-24 05:50:09 +00006426 // Go through the outputs.
6427 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006428 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006429
Anders Carlssonaaeef072010-01-24 05:50:09 +00006430 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006431 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006432
Anders Carlssonaaeef072010-01-24 05:50:09 +00006433 // Transform the output expr.
6434 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006435 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006436 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006437 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006438
Anders Carlssonaaeef072010-01-24 05:50:09 +00006439 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006440
John McCallb268a282010-08-23 23:25:46 +00006441 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006442 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006443
Anders Carlssonaaeef072010-01-24 05:50:09 +00006444 // Go through the inputs.
6445 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006446 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006447
Anders Carlssonaaeef072010-01-24 05:50:09 +00006448 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006449 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006450
Anders Carlssonaaeef072010-01-24 05:50:09 +00006451 // Transform the input expr.
6452 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006453 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006454 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006456
Anders Carlssonaaeef072010-01-24 05:50:09 +00006457 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006458
John McCallb268a282010-08-23 23:25:46 +00006459 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006461
Anders Carlssonaaeef072010-01-24 05:50:09 +00006462 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006463 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006464
6465 // Go through the clobbers.
6466 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006467 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006468
6469 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006470 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006471 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6472 S->isVolatile(), S->getNumOutputs(),
6473 S->getNumInputs(), Names.data(),
6474 Constraints, Exprs, AsmString.get(),
6475 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006476}
6477
Chad Rosier32503022012-06-11 20:47:18 +00006478template<typename Derived>
6479StmtResult
6480TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006481 ArrayRef<Token> AsmToks =
6482 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006483
John McCallf413f5e2013-05-03 00:10:13 +00006484 bool HadError = false, HadChange = false;
6485
6486 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6487 SmallVector<Expr*, 8> TransformedExprs;
6488 TransformedExprs.reserve(SrcExprs.size());
6489 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6490 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6491 if (!Result.isUsable()) {
6492 HadError = true;
6493 } else {
6494 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006495 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006496 }
6497 }
6498
6499 if (HadError) return StmtError();
6500 if (!HadChange && !getDerived().AlwaysRebuild())
6501 return Owned(S);
6502
Chad Rosierb6f46c12012-08-15 16:53:30 +00006503 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006504 AsmToks, S->getAsmString(),
6505 S->getNumOutputs(), S->getNumInputs(),
6506 S->getAllConstraints(), S->getClobbers(),
6507 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006508}
Douglas Gregorebe10102009-08-20 07:17:43 +00006509
Richard Smith9f690bd2015-10-27 06:02:45 +00006510// C++ Coroutines TS
6511
6512template<typename Derived>
6513StmtResult
6514TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6515 // The coroutine body should be re-formed by the caller if necessary.
6516 return getDerived().TransformStmt(S->getBody());
6517}
6518
6519template<typename Derived>
6520StmtResult
6521TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6522 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6523 /*NotCopyInit*/false);
6524 if (Result.isInvalid())
6525 return StmtError();
6526
6527 // Always rebuild; we don't know if this needs to be injected into a new
6528 // context or if the promise type has changed.
6529 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6530}
6531
6532template<typename Derived>
6533ExprResult
6534TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6535 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6536 /*NotCopyInit*/false);
6537 if (Result.isInvalid())
6538 return ExprError();
6539
6540 // Always rebuild; we don't know if this needs to be injected into a new
6541 // context or if the promise type has changed.
6542 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6543}
6544
6545template<typename Derived>
6546ExprResult
6547TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6548 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6549 /*NotCopyInit*/false);
6550 if (Result.isInvalid())
6551 return ExprError();
6552
6553 // Always rebuild; we don't know if this needs to be injected into a new
6554 // context or if the promise type has changed.
6555 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6556}
6557
6558// Objective-C Statements.
6559
Douglas Gregorebe10102009-08-20 07:17:43 +00006560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006561StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006562TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006563 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006564 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006565 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006566 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006567
Douglas Gregor96c79492010-04-23 22:50:49 +00006568 // Transform the @catch statements (if present).
6569 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006570 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006571 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006572 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006573 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006575 if (Catch.get() != S->getCatchStmt(I))
6576 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006577 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006579
Douglas Gregor306de2f2010-04-22 23:59:56 +00006580 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006581 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006582 if (S->getFinallyStmt()) {
6583 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6584 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006585 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006586 }
6587
6588 // If nothing changed, just retain this statement.
6589 if (!getDerived().AlwaysRebuild() &&
6590 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006591 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006592 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006593 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006594
Douglas Gregor306de2f2010-04-22 23:59:56 +00006595 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006596 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006597 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006598}
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregorebe10102009-08-20 07:17:43 +00006600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006601StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006602TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006603 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006604 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006605 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006606 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006607 if (FromVar->getTypeSourceInfo()) {
6608 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6609 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006612
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006613 QualType T;
6614 if (TSInfo)
6615 T = TSInfo->getType();
6616 else {
6617 T = getDerived().TransformType(FromVar->getType());
6618 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006619 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006621
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006622 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6623 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006626
John McCalldadc5752010-08-24 06:29:42 +00006627 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006628 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006629 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006630
6631 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006632 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006633 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006634}
Mike Stump11289f42009-09-09 15:08:12 +00006635
Douglas Gregorebe10102009-08-20 07:17:43 +00006636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006637StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006638TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006639 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006640 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006641 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006642 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006643
Douglas Gregor306de2f2010-04-22 23:59:56 +00006644 // If nothing changed, just retain this statement.
6645 if (!getDerived().AlwaysRebuild() &&
6646 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006647 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006648
6649 // Build a new statement.
6650 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006651 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006652}
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregorebe10102009-08-20 07:17:43 +00006654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006656TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006657 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006658 if (S->getThrowExpr()) {
6659 Operand = getDerived().TransformExpr(S->getThrowExpr());
6660 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006661 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006662 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006663
Douglas Gregor2900c162010-04-22 21:44:01 +00006664 if (!getDerived().AlwaysRebuild() &&
6665 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006666 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006667
John McCallb268a282010-08-23 23:25:46 +00006668 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006669}
Mike Stump11289f42009-09-09 15:08:12 +00006670
Douglas Gregorebe10102009-08-20 07:17:43 +00006671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006672StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006673TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006674 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006675 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006676 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006677 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006679 Object =
6680 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6681 Object.get());
6682 if (Object.isInvalid())
6683 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006684
Douglas Gregor6148de72010-04-22 22:01:21 +00006685 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006686 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006687 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006689
Douglas Gregor6148de72010-04-22 22:01:21 +00006690 // If nothing change, just retain the current statement.
6691 if (!getDerived().AlwaysRebuild() &&
6692 Object.get() == S->getSynchExpr() &&
6693 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006694 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006695
6696 // Build a new statement.
6697 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006698 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006699}
6700
6701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006702StmtResult
John McCall31168b02011-06-15 23:02:42 +00006703TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6704 ObjCAutoreleasePoolStmt *S) {
6705 // Transform the body.
6706 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6707 if (Body.isInvalid())
6708 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006709
John McCall31168b02011-06-15 23:02:42 +00006710 // If nothing changed, just retain this statement.
6711 if (!getDerived().AlwaysRebuild() &&
6712 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006713 return S;
John McCall31168b02011-06-15 23:02:42 +00006714
6715 // Build a new statement.
6716 return getDerived().RebuildObjCAutoreleasePoolStmt(
6717 S->getAtLoc(), Body.get());
6718}
6719
6720template<typename Derived>
6721StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006722TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006723 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006724 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006725 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006726 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006728
Douglas Gregorf68a5082010-04-22 23:10:45 +00006729 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006730 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006731 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregorf68a5082010-04-22 23:10:45 +00006734 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006735 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006736 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006738
Douglas Gregorf68a5082010-04-22 23:10:45 +00006739 // If nothing changed, just retain this statement.
6740 if (!getDerived().AlwaysRebuild() &&
6741 Element.get() == S->getElement() &&
6742 Collection.get() == S->getCollection() &&
6743 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006744 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006745
Douglas Gregorf68a5082010-04-22 23:10:45 +00006746 // Build a new statement.
6747 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006748 Element.get(),
6749 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006750 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006751 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006752}
6753
David Majnemer5f7efef2013-10-15 09:50:08 +00006754template <typename Derived>
6755StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006756 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006757 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006758 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6759 TypeSourceInfo *T =
6760 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006761 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006762 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006763
David Majnemer5f7efef2013-10-15 09:50:08 +00006764 Var = getDerived().RebuildExceptionDecl(
6765 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6766 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006767 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006768 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006769 }
Mike Stump11289f42009-09-09 15:08:12 +00006770
Douglas Gregorebe10102009-08-20 07:17:43 +00006771 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006772 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006773 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006775
David Majnemer5f7efef2013-10-15 09:50:08 +00006776 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006777 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006778 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006779
David Majnemer5f7efef2013-10-15 09:50:08 +00006780 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006781}
Mike Stump11289f42009-09-09 15:08:12 +00006782
David Majnemer5f7efef2013-10-15 09:50:08 +00006783template <typename Derived>
6784StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006785 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006786 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006787 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006788 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006789
Douglas Gregorebe10102009-08-20 07:17:43 +00006790 // Transform the handlers.
6791 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006792 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006793 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006794 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006795 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006797
Douglas Gregorebe10102009-08-20 07:17:43 +00006798 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006799 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006800 }
Mike Stump11289f42009-09-09 15:08:12 +00006801
David Majnemer5f7efef2013-10-15 09:50:08 +00006802 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006804 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006805
John McCallb268a282010-08-23 23:25:46 +00006806 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006807 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006808}
Mike Stump11289f42009-09-09 15:08:12 +00006809
Richard Smith02e85f32011-04-14 22:09:26 +00006810template<typename Derived>
6811StmtResult
6812TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6813 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6814 if (Range.isInvalid())
6815 return StmtError();
6816
6817 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6818 if (BeginEnd.isInvalid())
6819 return StmtError();
6820
6821 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6822 if (Cond.isInvalid())
6823 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006824 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006825 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006826 if (Cond.isInvalid())
6827 return StmtError();
6828 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006829 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006830
6831 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6832 if (Inc.isInvalid())
6833 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006834 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006835 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006836
6837 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6838 if (LoopVar.isInvalid())
6839 return StmtError();
6840
6841 StmtResult NewStmt = S;
6842 if (getDerived().AlwaysRebuild() ||
6843 Range.get() != S->getRangeStmt() ||
6844 BeginEnd.get() != S->getBeginEndStmt() ||
6845 Cond.get() != S->getCond() ||
6846 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006847 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006848 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006849 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006850 S->getColonLoc(), Range.get(),
6851 BeginEnd.get(), Cond.get(),
6852 Inc.get(), LoopVar.get(),
6853 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006854 if (NewStmt.isInvalid())
6855 return StmtError();
6856 }
Richard Smith02e85f32011-04-14 22:09:26 +00006857
6858 StmtResult Body = getDerived().TransformStmt(S->getBody());
6859 if (Body.isInvalid())
6860 return StmtError();
6861
6862 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6863 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006864 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006865 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006866 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006867 S->getColonLoc(), Range.get(),
6868 BeginEnd.get(), Cond.get(),
6869 Inc.get(), LoopVar.get(),
6870 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006871 if (NewStmt.isInvalid())
6872 return StmtError();
6873 }
Richard Smith02e85f32011-04-14 22:09:26 +00006874
6875 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006876 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006877
6878 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6879}
6880
John Wiegley1c0675e2011-04-28 01:08:34 +00006881template<typename Derived>
6882StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006883TreeTransform<Derived>::TransformMSDependentExistsStmt(
6884 MSDependentExistsStmt *S) {
6885 // Transform the nested-name-specifier, if any.
6886 NestedNameSpecifierLoc QualifierLoc;
6887 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006888 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006889 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6890 if (!QualifierLoc)
6891 return StmtError();
6892 }
6893
6894 // Transform the declaration name.
6895 DeclarationNameInfo NameInfo = S->getNameInfo();
6896 if (NameInfo.getName()) {
6897 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6898 if (!NameInfo.getName())
6899 return StmtError();
6900 }
6901
6902 // Check whether anything changed.
6903 if (!getDerived().AlwaysRebuild() &&
6904 QualifierLoc == S->getQualifierLoc() &&
6905 NameInfo.getName() == S->getNameInfo().getName())
6906 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006907
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006908 // Determine whether this name exists, if we can.
6909 CXXScopeSpec SS;
6910 SS.Adopt(QualifierLoc);
6911 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006912 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006913 case Sema::IER_Exists:
6914 if (S->isIfExists())
6915 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006916
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006917 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6918
6919 case Sema::IER_DoesNotExist:
6920 if (S->isIfNotExists())
6921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006922
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006923 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006924
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006925 case Sema::IER_Dependent:
6926 Dependent = true;
6927 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006928
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006929 case Sema::IER_Error:
6930 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006932
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006933 // We need to continue with the instantiation, so do so now.
6934 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6935 if (SubStmt.isInvalid())
6936 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006937
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006938 // If we have resolved the name, just transform to the substatement.
6939 if (!Dependent)
6940 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006941
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006942 // The name is still dependent, so build a dependent expression again.
6943 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6944 S->isIfExists(),
6945 QualifierLoc,
6946 NameInfo,
6947 SubStmt.get());
6948}
6949
6950template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006951ExprResult
6952TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6953 NestedNameSpecifierLoc QualifierLoc;
6954 if (E->getQualifierLoc()) {
6955 QualifierLoc
6956 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6957 if (!QualifierLoc)
6958 return ExprError();
6959 }
6960
6961 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6962 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6963 if (!PD)
6964 return ExprError();
6965
6966 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6967 if (Base.isInvalid())
6968 return ExprError();
6969
6970 return new (SemaRef.getASTContext())
6971 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6972 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6973 QualifierLoc, E->getMemberLoc());
6974}
6975
David Majnemerfad8f482013-10-15 09:33:02 +00006976template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00006977ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
6978 MSPropertySubscriptExpr *E) {
6979 auto BaseRes = getDerived().TransformExpr(E->getBase());
6980 if (BaseRes.isInvalid())
6981 return ExprError();
6982 auto IdxRes = getDerived().TransformExpr(E->getIdx());
6983 if (IdxRes.isInvalid())
6984 return ExprError();
6985
6986 if (!getDerived().AlwaysRebuild() &&
6987 BaseRes.get() == E->getBase() &&
6988 IdxRes.get() == E->getIdx())
6989 return E;
6990
6991 return getDerived().RebuildArraySubscriptExpr(
6992 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
6993}
6994
6995template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00006996StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006997 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006998 if (TryBlock.isInvalid())
6999 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007000
7001 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007002 if (Handler.isInvalid())
7003 return StmtError();
7004
David Majnemerfad8f482013-10-15 09:33:02 +00007005 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7006 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007007 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007008
Warren Huntf6be4cb2014-07-25 20:52:51 +00007009 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7010 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007011}
7012
David Majnemerfad8f482013-10-15 09:33:02 +00007013template <typename Derived>
7014StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007015 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007016 if (Block.isInvalid())
7017 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007018
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007019 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007020}
7021
David Majnemerfad8f482013-10-15 09:33:02 +00007022template <typename Derived>
7023StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007024 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007025 if (FilterExpr.isInvalid())
7026 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007027
David Majnemer7e755502013-10-15 09:30:14 +00007028 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007029 if (Block.isInvalid())
7030 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007031
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007032 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7033 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007034}
7035
David Majnemerfad8f482013-10-15 09:33:02 +00007036template <typename Derived>
7037StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7038 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007039 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7040 else
7041 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7042}
7043
Nico Weber9b982072014-07-07 00:12:30 +00007044template<typename Derived>
7045StmtResult
7046TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7047 return S;
7048}
7049
Alexander Musman64d33f12014-06-04 07:53:32 +00007050//===----------------------------------------------------------------------===//
7051// OpenMP directive transformation
7052//===----------------------------------------------------------------------===//
7053template <typename Derived>
7054StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7055 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007056
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007057 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007058 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007059 ArrayRef<OMPClause *> Clauses = D->clauses();
7060 TClauses.reserve(Clauses.size());
7061 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7062 I != E; ++I) {
7063 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007064 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007065 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007066 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007067 if (Clause)
7068 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007069 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007070 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007071 }
7072 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007073 StmtResult AssociatedStmt;
7074 if (D->hasAssociatedStmt()) {
7075 if (!D->getAssociatedStmt()) {
7076 return StmtError();
7077 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007078 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7079 /*CurScope=*/nullptr);
7080 StmtResult Body;
7081 {
7082 Sema::CompoundScopeRAII CompoundScope(getSema());
7083 Body = getDerived().TransformStmt(
7084 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7085 }
7086 AssociatedStmt =
7087 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007088 if (AssociatedStmt.isInvalid()) {
7089 return StmtError();
7090 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007091 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007092 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007093 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007094 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007095
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007096 // Transform directive name for 'omp critical' directive.
7097 DeclarationNameInfo DirName;
7098 if (D->getDirectiveKind() == OMPD_critical) {
7099 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7100 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7101 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007102 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7103 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7104 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007105 } else if (D->getDirectiveKind() == OMPD_cancel) {
7106 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007107 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007108
Alexander Musman64d33f12014-06-04 07:53:32 +00007109 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007110 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7111 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007112}
7113
Alexander Musman64d33f12014-06-04 07:53:32 +00007114template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007115StmtResult
7116TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7117 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007118 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7119 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7122 return Res;
7123}
7124
Alexander Musman64d33f12014-06-04 07:53:32 +00007125template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007126StmtResult
7127TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7128 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007129 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7130 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007133 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007134}
7135
Alexey Bataevf29276e2014-06-18 04:14:57 +00007136template <typename Derived>
7137StmtResult
7138TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7139 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007140 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7141 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7144 return Res;
7145}
7146
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007147template <typename Derived>
7148StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007149TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7150 DeclarationNameInfo DirName;
7151 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7152 D->getLocStart());
7153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7155 return Res;
7156}
7157
7158template <typename Derived>
7159StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007160TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7161 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007162 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7163 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7166 return Res;
7167}
7168
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007169template <typename Derived>
7170StmtResult
7171TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7172 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007173 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7174 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7177 return Res;
7178}
7179
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007180template <typename Derived>
7181StmtResult
7182TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7183 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007184 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7185 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7188 return Res;
7189}
7190
Alexey Bataev4acb8592014-07-07 13:01:15 +00007191template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007192StmtResult
7193TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7194 DeclarationNameInfo DirName;
7195 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7196 D->getLocStart());
7197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7199 return Res;
7200}
7201
7202template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007203StmtResult
7204TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7205 getDerived().getSema().StartOpenMPDSABlock(
7206 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7207 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7209 return Res;
7210}
7211
7212template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007213StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7214 OMPParallelForDirective *D) {
7215 DeclarationNameInfo DirName;
7216 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7217 nullptr, D->getLocStart());
7218 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7219 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7220 return Res;
7221}
7222
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007223template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007224StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7225 OMPParallelForSimdDirective *D) {
7226 DeclarationNameInfo DirName;
7227 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7228 nullptr, D->getLocStart());
7229 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7230 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7231 return Res;
7232}
7233
7234template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007235StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7236 OMPParallelSectionsDirective *D) {
7237 DeclarationNameInfo DirName;
7238 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7239 nullptr, D->getLocStart());
7240 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7241 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7242 return Res;
7243}
7244
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007245template <typename Derived>
7246StmtResult
7247TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7248 DeclarationNameInfo DirName;
7249 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7250 D->getLocStart());
7251 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7252 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7253 return Res;
7254}
7255
Alexey Bataev68446b72014-07-18 07:47:19 +00007256template <typename Derived>
7257StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7258 OMPTaskyieldDirective *D) {
7259 DeclarationNameInfo DirName;
7260 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7261 D->getLocStart());
7262 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7263 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7264 return Res;
7265}
7266
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007267template <typename Derived>
7268StmtResult
7269TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7270 DeclarationNameInfo DirName;
7271 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7272 D->getLocStart());
7273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7275 return Res;
7276}
7277
Alexey Bataev2df347a2014-07-18 10:17:07 +00007278template <typename Derived>
7279StmtResult
7280TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7281 DeclarationNameInfo DirName;
7282 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7283 D->getLocStart());
7284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7286 return Res;
7287}
7288
Alexey Bataev6125da92014-07-21 11:26:11 +00007289template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007290StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7291 OMPTaskgroupDirective *D) {
7292 DeclarationNameInfo DirName;
7293 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, 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 Bataev6125da92014-07-21 11:26:11 +00007301StmtResult
7302TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7303 DeclarationNameInfo DirName;
7304 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7305 D->getLocStart());
7306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7308 return Res;
7309}
7310
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007311template <typename Derived>
7312StmtResult
7313TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7314 DeclarationNameInfo DirName;
7315 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7316 D->getLocStart());
7317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7319 return Res;
7320}
7321
Alexey Bataev0162e452014-07-22 10:10:35 +00007322template <typename Derived>
7323StmtResult
7324TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7325 DeclarationNameInfo DirName;
7326 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7327 D->getLocStart());
7328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7329 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7330 return Res;
7331}
7332
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007333template <typename Derived>
7334StmtResult
7335TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7336 DeclarationNameInfo DirName;
7337 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7338 D->getLocStart());
7339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7340 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7341 return Res;
7342}
7343
Alexey Bataev13314bf2014-10-09 04:18:56 +00007344template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007345StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7346 OMPTargetDataDirective *D) {
7347 DeclarationNameInfo DirName;
7348 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7349 D->getLocStart());
7350 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7351 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7352 return Res;
7353}
7354
7355template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007356StmtResult
7357TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7358 DeclarationNameInfo DirName;
7359 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7360 D->getLocStart());
7361 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7362 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7363 return Res;
7364}
7365
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007366template <typename Derived>
7367StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7368 OMPCancellationPointDirective *D) {
7369 DeclarationNameInfo DirName;
7370 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7371 nullptr, D->getLocStart());
7372 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7373 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7374 return Res;
7375}
7376
Alexey Bataev80909872015-07-02 11:25:17 +00007377template <typename Derived>
7378StmtResult
7379TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7380 DeclarationNameInfo DirName;
7381 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7382 D->getLocStart());
7383 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7384 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7385 return Res;
7386}
7387
Alexey Bataev49f6e782015-12-01 04:18:41 +00007388template <typename Derived>
7389StmtResult
7390TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7391 DeclarationNameInfo DirName;
7392 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7393 D->getLocStart());
7394 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7395 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7396 return Res;
7397}
7398
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007399template <typename Derived>
7400StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7401 OMPTaskLoopSimdDirective *D) {
7402 DeclarationNameInfo DirName;
7403 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7404 nullptr, D->getLocStart());
7405 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7406 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7407 return Res;
7408}
7409
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007410template <typename Derived>
7411StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7412 OMPDistributeDirective *D) {
7413 DeclarationNameInfo DirName;
7414 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7415 D->getLocStart());
7416 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7417 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7418 return Res;
7419}
7420
Alexander Musman64d33f12014-06-04 07:53:32 +00007421//===----------------------------------------------------------------------===//
7422// OpenMP clause transformation
7423//===----------------------------------------------------------------------===//
7424template <typename Derived>
7425OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007426 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7427 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007428 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007429 return getDerived().RebuildOMPIfClause(
7430 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7431 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007432}
7433
Alexander Musman64d33f12014-06-04 07:53:32 +00007434template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007435OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7436 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7437 if (Cond.isInvalid())
7438 return nullptr;
7439 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7440 C->getLParenLoc(), C->getLocEnd());
7441}
7442
7443template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007444OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007445TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7446 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7447 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007448 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007449 return getDerived().RebuildOMPNumThreadsClause(
7450 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007451}
7452
Alexey Bataev62c87d22014-03-21 04:51:18 +00007453template <typename Derived>
7454OMPClause *
7455TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7456 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7457 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007458 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007459 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007460 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007461}
7462
Alexander Musman8bd31e62014-05-27 15:12:19 +00007463template <typename Derived>
7464OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007465TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7466 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7467 if (E.isInvalid())
7468 return nullptr;
7469 return getDerived().RebuildOMPSimdlenClause(
7470 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7471}
7472
7473template <typename Derived>
7474OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007475TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7476 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7477 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007478 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007479 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007480 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007481}
7482
Alexander Musman64d33f12014-06-04 07:53:32 +00007483template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007484OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007485TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007486 return getDerived().RebuildOMPDefaultClause(
7487 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7488 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007489}
7490
Alexander Musman64d33f12014-06-04 07:53:32 +00007491template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007492OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007493TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007494 return getDerived().RebuildOMPProcBindClause(
7495 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7496 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007497}
7498
Alexander Musman64d33f12014-06-04 07:53:32 +00007499template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007500OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007501TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7502 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7503 if (E.isInvalid())
7504 return nullptr;
7505 return getDerived().RebuildOMPScheduleClause(
7506 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7507 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7508}
7509
7510template <typename Derived>
7511OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007512TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007513 ExprResult E;
7514 if (auto *Num = C->getNumForLoops()) {
7515 E = getDerived().TransformExpr(Num);
7516 if (E.isInvalid())
7517 return nullptr;
7518 }
7519 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7520 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007521}
7522
7523template <typename Derived>
7524OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007525TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7526 // No need to rebuild this clause, no template-dependent parameters.
7527 return C;
7528}
7529
7530template <typename Derived>
7531OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007532TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7533 // No need to rebuild this clause, no template-dependent parameters.
7534 return C;
7535}
7536
7537template <typename Derived>
7538OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007539TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7540 // No need to rebuild this clause, no template-dependent parameters.
7541 return C;
7542}
7543
7544template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007545OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7546 // No need to rebuild this clause, no template-dependent parameters.
7547 return C;
7548}
7549
7550template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007551OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7552 // No need to rebuild this clause, no template-dependent parameters.
7553 return C;
7554}
7555
7556template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007557OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007558TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7559 // No need to rebuild this clause, no template-dependent parameters.
7560 return C;
7561}
7562
7563template <typename Derived>
7564OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007565TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7566 // No need to rebuild this clause, no template-dependent parameters.
7567 return C;
7568}
7569
7570template <typename Derived>
7571OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007572TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7573 // No need to rebuild this clause, no template-dependent parameters.
7574 return C;
7575}
7576
7577template <typename Derived>
7578OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007579TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7580 // No need to rebuild this clause, no template-dependent parameters.
7581 return C;
7582}
7583
7584template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007585OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7586 // No need to rebuild this clause, no template-dependent parameters.
7587 return C;
7588}
7589
7590template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007591OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007592TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7593 // No need to rebuild this clause, no template-dependent parameters.
7594 return C;
7595}
7596
7597template <typename Derived>
7598OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007599TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007600 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007601 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007602 for (auto *VE : C->varlists()) {
7603 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007604 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007605 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007606 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007607 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007608 return getDerived().RebuildOMPPrivateClause(
7609 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007610}
7611
Alexander Musman64d33f12014-06-04 07:53:32 +00007612template <typename Derived>
7613OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7614 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007615 llvm::SmallVector<Expr *, 16> Vars;
7616 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007617 for (auto *VE : C->varlists()) {
7618 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007619 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007620 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007621 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007622 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007623 return getDerived().RebuildOMPFirstprivateClause(
7624 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007625}
7626
Alexander Musman64d33f12014-06-04 07:53:32 +00007627template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007628OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007629TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7630 llvm::SmallVector<Expr *, 16> Vars;
7631 Vars.reserve(C->varlist_size());
7632 for (auto *VE : C->varlists()) {
7633 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7634 if (EVar.isInvalid())
7635 return nullptr;
7636 Vars.push_back(EVar.get());
7637 }
7638 return getDerived().RebuildOMPLastprivateClause(
7639 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7640}
7641
7642template <typename Derived>
7643OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007644TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7645 llvm::SmallVector<Expr *, 16> Vars;
7646 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007647 for (auto *VE : C->varlists()) {
7648 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007649 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007650 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007651 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007652 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007653 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7654 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007655}
7656
Alexander Musman64d33f12014-06-04 07:53:32 +00007657template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007658OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007659TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7660 llvm::SmallVector<Expr *, 16> Vars;
7661 Vars.reserve(C->varlist_size());
7662 for (auto *VE : C->varlists()) {
7663 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7664 if (EVar.isInvalid())
7665 return nullptr;
7666 Vars.push_back(EVar.get());
7667 }
7668 CXXScopeSpec ReductionIdScopeSpec;
7669 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7670
7671 DeclarationNameInfo NameInfo = C->getNameInfo();
7672 if (NameInfo.getName()) {
7673 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7674 if (!NameInfo.getName())
7675 return nullptr;
7676 }
7677 return getDerived().RebuildOMPReductionClause(
7678 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7679 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7680}
7681
7682template <typename Derived>
7683OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007684TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7685 llvm::SmallVector<Expr *, 16> Vars;
7686 Vars.reserve(C->varlist_size());
7687 for (auto *VE : C->varlists()) {
7688 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7689 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007690 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007691 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007692 }
7693 ExprResult Step = getDerived().TransformExpr(C->getStep());
7694 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007695 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007696 return getDerived().RebuildOMPLinearClause(
7697 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7698 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007699}
7700
Alexander Musman64d33f12014-06-04 07:53:32 +00007701template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007702OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007703TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7704 llvm::SmallVector<Expr *, 16> Vars;
7705 Vars.reserve(C->varlist_size());
7706 for (auto *VE : C->varlists()) {
7707 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7708 if (EVar.isInvalid())
7709 return nullptr;
7710 Vars.push_back(EVar.get());
7711 }
7712 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7713 if (Alignment.isInvalid())
7714 return nullptr;
7715 return getDerived().RebuildOMPAlignedClause(
7716 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7717 C->getColonLoc(), C->getLocEnd());
7718}
7719
Alexander Musman64d33f12014-06-04 07:53:32 +00007720template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007721OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007722TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7723 llvm::SmallVector<Expr *, 16> Vars;
7724 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007725 for (auto *VE : C->varlists()) {
7726 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007727 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007728 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007729 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007730 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007731 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7732 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007733}
7734
Alexey Bataevbae9a792014-06-27 10:37:06 +00007735template <typename Derived>
7736OMPClause *
7737TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7738 llvm::SmallVector<Expr *, 16> Vars;
7739 Vars.reserve(C->varlist_size());
7740 for (auto *VE : C->varlists()) {
7741 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7742 if (EVar.isInvalid())
7743 return nullptr;
7744 Vars.push_back(EVar.get());
7745 }
7746 return getDerived().RebuildOMPCopyprivateClause(
7747 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7748}
7749
Alexey Bataev6125da92014-07-21 11:26:11 +00007750template <typename Derived>
7751OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7752 llvm::SmallVector<Expr *, 16> Vars;
7753 Vars.reserve(C->varlist_size());
7754 for (auto *VE : C->varlists()) {
7755 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7756 if (EVar.isInvalid())
7757 return nullptr;
7758 Vars.push_back(EVar.get());
7759 }
7760 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7761 C->getLParenLoc(), C->getLocEnd());
7762}
7763
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007764template <typename Derived>
7765OMPClause *
7766TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7767 llvm::SmallVector<Expr *, 16> Vars;
7768 Vars.reserve(C->varlist_size());
7769 for (auto *VE : C->varlists()) {
7770 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7771 if (EVar.isInvalid())
7772 return nullptr;
7773 Vars.push_back(EVar.get());
7774 }
7775 return getDerived().RebuildOMPDependClause(
7776 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7777 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7778}
7779
Michael Wonge710d542015-08-07 16:16:36 +00007780template <typename Derived>
7781OMPClause *
7782TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7783 ExprResult E = getDerived().TransformExpr(C->getDevice());
7784 if (E.isInvalid())
7785 return nullptr;
7786 return getDerived().RebuildOMPDeviceClause(
7787 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7788}
7789
Kelvin Li0bff7af2015-11-23 05:32:03 +00007790template <typename Derived>
7791OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7792 llvm::SmallVector<Expr *, 16> Vars;
7793 Vars.reserve(C->varlist_size());
7794 for (auto *VE : C->varlists()) {
7795 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7796 if (EVar.isInvalid())
7797 return nullptr;
7798 Vars.push_back(EVar.get());
7799 }
7800 return getDerived().RebuildOMPMapClause(
7801 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7802 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7803 C->getLocEnd());
7804}
7805
Kelvin Li099bb8c2015-11-24 20:50:12 +00007806template <typename Derived>
7807OMPClause *
7808TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7809 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7810 if (E.isInvalid())
7811 return nullptr;
7812 return getDerived().RebuildOMPNumTeamsClause(
7813 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7814}
7815
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007816template <typename Derived>
7817OMPClause *
7818TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7819 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7820 if (E.isInvalid())
7821 return nullptr;
7822 return getDerived().RebuildOMPThreadLimitClause(
7823 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7824}
7825
Alexey Bataeva0569352015-12-01 10:17:31 +00007826template <typename Derived>
7827OMPClause *
7828TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7829 ExprResult E = getDerived().TransformExpr(C->getPriority());
7830 if (E.isInvalid())
7831 return nullptr;
7832 return getDerived().RebuildOMPPriorityClause(
7833 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7834}
7835
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007836template <typename Derived>
7837OMPClause *
7838TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7839 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7840 if (E.isInvalid())
7841 return nullptr;
7842 return getDerived().RebuildOMPGrainsizeClause(
7843 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7844}
7845
Alexey Bataev382967a2015-12-08 12:06:20 +00007846template <typename Derived>
7847OMPClause *
7848TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7849 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7850 if (E.isInvalid())
7851 return nullptr;
7852 return getDerived().RebuildOMPNumTasksClause(
7853 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7854}
7855
Alexey Bataev28c75412015-12-15 08:19:24 +00007856template <typename Derived>
7857OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7858 ExprResult E = getDerived().TransformExpr(C->getHint());
7859 if (E.isInvalid())
7860 return nullptr;
7861 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7862 C->getLParenLoc(), C->getLocEnd());
7863}
7864
Douglas Gregorebe10102009-08-20 07:17:43 +00007865//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007866// Expression transformation
7867//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007870TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007871 if (!E->isTypeDependent())
7872 return E;
7873
7874 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7875 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007876}
Mike Stump11289f42009-09-09 15:08:12 +00007877
7878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007879ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007880TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007881 NestedNameSpecifierLoc QualifierLoc;
7882 if (E->getQualifierLoc()) {
7883 QualifierLoc
7884 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7885 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007886 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007887 }
John McCallce546572009-12-08 09:08:17 +00007888
7889 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007890 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7891 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007892 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007894
John McCall815039a2010-08-17 21:27:17 +00007895 DeclarationNameInfo NameInfo = E->getNameInfo();
7896 if (NameInfo.getName()) {
7897 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7898 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007899 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007900 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007901
7902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007903 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007904 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007905 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007906 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007907
7908 // Mark it referenced in the new context regardless.
7909 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007910 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007911
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007912 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007913 }
John McCallce546572009-12-08 09:08:17 +00007914
Craig Topperc3ec1492014-05-26 06:22:03 +00007915 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007916 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007917 TemplateArgs = &TransArgs;
7918 TransArgs.setLAngleLoc(E->getLAngleLoc());
7919 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007920 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7921 E->getNumTemplateArgs(),
7922 TransArgs))
7923 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007924 }
7925
Chad Rosier1dcde962012-08-08 18:46:20 +00007926 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007927 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007928}
Mike Stump11289f42009-09-09 15:08:12 +00007929
Douglas Gregora16548e2009-08-11 05:31:07 +00007930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007932TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007933 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007934}
Mike Stump11289f42009-09-09 15:08:12 +00007935
Douglas Gregora16548e2009-08-11 05:31:07 +00007936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007938TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007939 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007940}
Mike Stump11289f42009-09-09 15:08:12 +00007941
Douglas Gregora16548e2009-08-11 05:31:07 +00007942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007944TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007945 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007946}
Mike Stump11289f42009-09-09 15:08:12 +00007947
Douglas Gregora16548e2009-08-11 05:31:07 +00007948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007950TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007951 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007952}
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007956TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007957 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007958}
7959
7960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007961ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007962TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007963 if (FunctionDecl *FD = E->getDirectCallee())
7964 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007965 return SemaRef.MaybeBindToTemporary(E);
7966}
7967
7968template<typename Derived>
7969ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007970TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7971 ExprResult ControllingExpr =
7972 getDerived().TransformExpr(E->getControllingExpr());
7973 if (ControllingExpr.isInvalid())
7974 return ExprError();
7975
Chris Lattner01cf8db2011-07-20 06:58:45 +00007976 SmallVector<Expr *, 4> AssocExprs;
7977 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007978 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7979 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7980 if (TS) {
7981 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7982 if (!AssocType)
7983 return ExprError();
7984 AssocTypes.push_back(AssocType);
7985 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007986 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007987 }
7988
7989 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7990 if (AssocExpr.isInvalid())
7991 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007992 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007993 }
7994
7995 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7996 E->getDefaultLoc(),
7997 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007998 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007999 AssocTypes,
8000 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008001}
8002
8003template<typename Derived>
8004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008005TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008006 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008007 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008009
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008011 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008012
John McCallb268a282010-08-23 23:25:46 +00008013 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008014 E->getRParen());
8015}
8016
Richard Smithdb2630f2012-10-21 03:28:35 +00008017/// \brief The operand of a unary address-of operator has special rules: it's
8018/// allowed to refer to a non-static member of a class even if there's no 'this'
8019/// object available.
8020template<typename Derived>
8021ExprResult
8022TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8023 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008024 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008025 else
8026 return getDerived().TransformExpr(E);
8027}
8028
Mike Stump11289f42009-09-09 15:08:12 +00008029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008030ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008031TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008032 ExprResult SubExpr;
8033 if (E->getOpcode() == UO_AddrOf)
8034 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8035 else
8036 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008037 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008039
Douglas Gregora16548e2009-08-11 05:31:07 +00008040 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008041 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008042
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8044 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008045 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008046}
Mike Stump11289f42009-09-09 15:08:12 +00008047
Douglas Gregora16548e2009-08-11 05:31:07 +00008048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008049ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008050TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8051 // Transform the type.
8052 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8053 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008054 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008055
Douglas Gregor882211c2010-04-28 22:16:22 +00008056 // Transform all of the components into components similar to what the
8057 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008058 // FIXME: It would be slightly more efficient in the non-dependent case to
8059 // just map FieldDecls, rather than requiring the rebuilder to look for
8060 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008061 // template code that we don't care.
8062 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008063 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00008064 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008065 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008066 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8067 const Node &ON = E->getComponent(I);
8068 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008069 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008070 Comp.LocStart = ON.getSourceRange().getBegin();
8071 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008072 switch (ON.getKind()) {
8073 case Node::Array: {
8074 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008075 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008076 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008077 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008078
Douglas Gregor882211c2010-04-28 22:16:22 +00008079 ExprChanged = ExprChanged || Index.get() != FromIndex;
8080 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008081 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008082 break;
8083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008084
Douglas Gregor882211c2010-04-28 22:16:22 +00008085 case Node::Field:
8086 case Node::Identifier:
8087 Comp.isBrackets = false;
8088 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008089 if (!Comp.U.IdentInfo)
8090 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008091
Douglas Gregor882211c2010-04-28 22:16:22 +00008092 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008093
Douglas Gregord1702062010-04-29 00:18:15 +00008094 case Node::Base:
8095 // Will be recomputed during the rebuild.
8096 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008098
Douglas Gregor882211c2010-04-28 22:16:22 +00008099 Components.push_back(Comp);
8100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008101
Douglas Gregor882211c2010-04-28 22:16:22 +00008102 // If nothing changed, retain the existing expression.
8103 if (!getDerived().AlwaysRebuild() &&
8104 Type == E->getTypeSourceInfo() &&
8105 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008106 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008107
Douglas Gregor882211c2010-04-28 22:16:22 +00008108 // Build a new offsetof expression.
8109 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008110 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008111}
8112
8113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008114ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008115TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008116 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008117 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008118 return E;
John McCall8d69a212010-11-15 23:31:06 +00008119}
8120
8121template<typename Derived>
8122ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008123TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8124 return E;
8125}
8126
8127template<typename Derived>
8128ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008129TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008130 // Rebuild the syntactic form. The original syntactic form has
8131 // opaque-value expressions in it, so strip those away and rebuild
8132 // the result. This is a really awful way of doing this, but the
8133 // better solution (rebuilding the semantic expressions and
8134 // rebinding OVEs as necessary) doesn't work; we'd need
8135 // TreeTransform to not strip away implicit conversions.
8136 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8137 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008138 if (result.isInvalid()) return ExprError();
8139
8140 // If that gives us a pseudo-object result back, the pseudo-object
8141 // expression must have been an lvalue-to-rvalue conversion which we
8142 // should reapply.
8143 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008144 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008145
8146 return result;
8147}
8148
8149template<typename Derived>
8150ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008151TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8152 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008153 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008154 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008155
John McCallbcd03502009-12-07 02:54:59 +00008156 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008157 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008159
John McCall4c98fd82009-11-04 07:28:41 +00008160 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008161 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008162
Peter Collingbournee190dee2011-03-11 19:24:49 +00008163 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8164 E->getKind(),
8165 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008166 }
Mike Stump11289f42009-09-09 15:08:12 +00008167
Eli Friedmane4f22df2012-02-29 04:03:55 +00008168 // C++0x [expr.sizeof]p1:
8169 // The operand is either an expression, which is an unevaluated operand
8170 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008171 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8172 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008173
Reid Kleckner32506ed2014-06-12 23:03:48 +00008174 // Try to recover if we have something like sizeof(T::X) where X is a type.
8175 // Notably, there must be *exactly* one set of parens if X is a type.
8176 TypeSourceInfo *RecoveryTSI = nullptr;
8177 ExprResult SubExpr;
8178 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8179 if (auto *DRE =
8180 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8181 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8182 PE, DRE, false, &RecoveryTSI);
8183 else
8184 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8185
8186 if (RecoveryTSI) {
8187 return getDerived().RebuildUnaryExprOrTypeTrait(
8188 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8189 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008191
Eli Friedmane4f22df2012-02-29 04:03:55 +00008192 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008193 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008194
Peter Collingbournee190dee2011-03-11 19:24:49 +00008195 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8196 E->getOperatorLoc(),
8197 E->getKind(),
8198 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008199}
Mike Stump11289f42009-09-09 15:08:12 +00008200
Douglas Gregora16548e2009-08-11 05:31:07 +00008201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008203TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008204 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008207
John McCalldadc5752010-08-24 06:29:42 +00008208 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008209 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008211
8212
Douglas Gregora16548e2009-08-11 05:31:07 +00008213 if (!getDerived().AlwaysRebuild() &&
8214 LHS.get() == E->getLHS() &&
8215 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008216 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008217
John McCallb268a282010-08-23 23:25:46 +00008218 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008220 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 E->getRBracketLoc());
8222}
Mike Stump11289f42009-09-09 15:08:12 +00008223
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008224template <typename Derived>
8225ExprResult
8226TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8227 ExprResult Base = getDerived().TransformExpr(E->getBase());
8228 if (Base.isInvalid())
8229 return ExprError();
8230
8231 ExprResult LowerBound;
8232 if (E->getLowerBound()) {
8233 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8234 if (LowerBound.isInvalid())
8235 return ExprError();
8236 }
8237
8238 ExprResult Length;
8239 if (E->getLength()) {
8240 Length = getDerived().TransformExpr(E->getLength());
8241 if (Length.isInvalid())
8242 return ExprError();
8243 }
8244
8245 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8246 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8247 return E;
8248
8249 return getDerived().RebuildOMPArraySectionExpr(
8250 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8251 Length.get(), E->getRBracketLoc());
8252}
8253
Mike Stump11289f42009-09-09 15:08:12 +00008254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008256TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008257 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008258 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008260 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008261
8262 // Transform arguments.
8263 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008264 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008265 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008266 &ArgChanged))
8267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008268
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 if (!getDerived().AlwaysRebuild() &&
8270 Callee.get() == E->getCallee() &&
8271 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008272 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008275 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008277 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008278 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008279 E->getRParenLoc());
8280}
Mike Stump11289f42009-09-09 15:08:12 +00008281
8282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008284TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008285 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008288
Douglas Gregorea972d32011-02-28 21:54:11 +00008289 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008290 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008291 QualifierLoc
8292 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008293
Douglas Gregorea972d32011-02-28 21:54:11 +00008294 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008295 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008296 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008297 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008298
Eli Friedman2cfcef62009-12-04 06:40:45 +00008299 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008300 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8301 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008304
John McCall16df1e52010-03-30 21:47:33 +00008305 NamedDecl *FoundDecl = E->getFoundDecl();
8306 if (FoundDecl == E->getMemberDecl()) {
8307 FoundDecl = Member;
8308 } else {
8309 FoundDecl = cast_or_null<NamedDecl>(
8310 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8311 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008312 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008313 }
8314
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 if (!getDerived().AlwaysRebuild() &&
8316 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008317 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008318 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008319 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008320 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008321
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008322 // Mark it referenced in the new context regardless.
8323 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008324 SemaRef.MarkMemberReferenced(E);
8325
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008326 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008327 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008328
John McCall6b51f282009-11-23 01:53:49 +00008329 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008330 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008331 TransArgs.setLAngleLoc(E->getLAngleLoc());
8332 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008333 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8334 E->getNumTemplateArgs(),
8335 TransArgs))
8336 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008338
Douglas Gregora16548e2009-08-11 05:31:07 +00008339 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008340 SourceLocation FakeOperatorLoc =
8341 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008342
John McCall38836f02010-01-15 08:34:02 +00008343 // FIXME: to do this check properly, we will need to preserve the
8344 // first-qualifier-in-scope here, just in case we had a dependent
8345 // base (and therefore couldn't do the check) and a
8346 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008347 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008348
John McCallb268a282010-08-23 23:25:46 +00008349 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008351 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008352 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008353 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008354 Member,
John McCall16df1e52010-03-30 21:47:33 +00008355 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008356 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008357 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008358 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008359}
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008363TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008364 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008365 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008367
John McCalldadc5752010-08-24 06:29:42 +00008368 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008371
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 if (!getDerived().AlwaysRebuild() &&
8373 LHS.get() == E->getLHS() &&
8374 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008376
Lang Hames5de91cc2012-10-02 04:45:10 +00008377 Sema::FPContractStateRAII FPContractState(getSema());
8378 getSema().FPFeatures.fp_contract = E->isFPContractable();
8379
Douglas Gregora16548e2009-08-11 05:31:07 +00008380 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008381 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008382}
8383
Mike Stump11289f42009-09-09 15:08:12 +00008384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008385ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008386TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008387 CompoundAssignOperator *E) {
8388 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008389}
Mike Stump11289f42009-09-09 15:08:12 +00008390
Douglas Gregora16548e2009-08-11 05:31:07 +00008391template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008392ExprResult TreeTransform<Derived>::
8393TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8394 // Just rebuild the common and RHS expressions and see whether we
8395 // get any changes.
8396
8397 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8398 if (commonExpr.isInvalid())
8399 return ExprError();
8400
8401 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8402 if (rhs.isInvalid())
8403 return ExprError();
8404
8405 if (!getDerived().AlwaysRebuild() &&
8406 commonExpr.get() == e->getCommon() &&
8407 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008408 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008409
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008410 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008411 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008412 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008413 e->getColonLoc(),
8414 rhs.get());
8415}
8416
8417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008419TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008420 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008423
John McCalldadc5752010-08-24 06:29:42 +00008424 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008425 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008427
John McCalldadc5752010-08-24 06:29:42 +00008428 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008429 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008431
Douglas Gregora16548e2009-08-11 05:31:07 +00008432 if (!getDerived().AlwaysRebuild() &&
8433 Cond.get() == E->getCond() &&
8434 LHS.get() == E->getLHS() &&
8435 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008436 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008437
John McCallb268a282010-08-23 23:25:46 +00008438 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008439 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008440 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008441 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008442 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443}
Mike Stump11289f42009-09-09 15:08:12 +00008444
8445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008447TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008448 // Implicit casts are eliminated during transformation, since they
8449 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008450 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008451}
Mike Stump11289f42009-09-09 15:08:12 +00008452
Douglas Gregora16548e2009-08-11 05:31:07 +00008453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008455TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008456 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8457 if (!Type)
8458 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008459
John McCalldadc5752010-08-24 06:29:42 +00008460 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008461 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008462 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008464
Douglas Gregora16548e2009-08-11 05:31:07 +00008465 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008466 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008467 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008468 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008469
John McCall97513962010-01-15 18:39:57 +00008470 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008471 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008472 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008473 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008474}
Mike Stump11289f42009-09-09 15:08:12 +00008475
Douglas Gregora16548e2009-08-11 05:31:07 +00008476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008478TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008479 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8480 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8481 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008483
John McCalldadc5752010-08-24 06:29:42 +00008484 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008485 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008487
Douglas Gregora16548e2009-08-11 05:31:07 +00008488 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008489 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008491 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008492
John McCall5d7aa7f2010-01-19 22:33:45 +00008493 // Note: the expression type doesn't necessarily match the
8494 // type-as-written, but that's okay, because it should always be
8495 // derivable from the initializer.
8496
John McCalle15bbff2010-01-18 19:35:47 +00008497 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008498 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008499 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008500}
Mike Stump11289f42009-09-09 15:08:12 +00008501
Douglas Gregora16548e2009-08-11 05:31:07 +00008502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008504TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008505 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008506 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008508
Douglas Gregora16548e2009-08-11 05:31:07 +00008509 if (!getDerived().AlwaysRebuild() &&
8510 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008511 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008512
Douglas Gregora16548e2009-08-11 05:31:07 +00008513 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008514 SourceLocation FakeOperatorLoc =
8515 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008516 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008517 E->getAccessorLoc(),
8518 E->getAccessor());
8519}
Mike Stump11289f42009-09-09 15:08:12 +00008520
Douglas Gregora16548e2009-08-11 05:31:07 +00008521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008523TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008524 if (InitListExpr *Syntactic = E->getSyntacticForm())
8525 E = Syntactic;
8526
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008528
Benjamin Kramerf0623432012-08-23 22:51:59 +00008529 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008530 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008531 Inits, &InitChanged))
8532 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008533
Richard Smith520449d2015-02-05 06:15:50 +00008534 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8535 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8536 // in some cases. We can't reuse it in general, because the syntactic and
8537 // semantic forms are linked, and we can't know that semantic form will
8538 // match even if the syntactic form does.
8539 }
Mike Stump11289f42009-09-09 15:08:12 +00008540
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008541 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008542 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008543}
Mike Stump11289f42009-09-09 15:08:12 +00008544
Douglas Gregora16548e2009-08-11 05:31:07 +00008545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008547TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008548 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008549
Douglas Gregorebe10102009-08-20 07:17:43 +00008550 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008551 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008552 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008554
Douglas Gregorebe10102009-08-20 07:17:43 +00008555 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008556 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 bool ExprChanged = false;
8558 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8559 DEnd = E->designators_end();
8560 D != DEnd; ++D) {
8561 if (D->isFieldDesignator()) {
8562 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8563 D->getDotLoc(),
8564 D->getFieldLoc()));
8565 continue;
8566 }
Mike Stump11289f42009-09-09 15:08:12 +00008567
Douglas Gregora16548e2009-08-11 05:31:07 +00008568 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008569 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008570 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008572
8573 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008575
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008577 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 continue;
8579 }
Mike Stump11289f42009-09-09 15:08:12 +00008580
Douglas Gregora16548e2009-08-11 05:31:07 +00008581 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008582 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8584 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008586
John McCalldadc5752010-08-24 06:29:42 +00008587 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008588 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008589 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008590
8591 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008592 End.get(),
8593 D->getLBracketLoc(),
8594 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008595
Douglas Gregora16548e2009-08-11 05:31:07 +00008596 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8597 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008598
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008599 ArrayExprs.push_back(Start.get());
8600 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008601 }
Mike Stump11289f42009-09-09 15:08:12 +00008602
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 if (!getDerived().AlwaysRebuild() &&
8604 Init.get() == E->getInit() &&
8605 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008606 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008607
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008608 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008609 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008610 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008611}
Mike Stump11289f42009-09-09 15:08:12 +00008612
Yunzhong Gaocb779302015-06-10 00:27:52 +00008613// Seems that if TransformInitListExpr() only works on the syntactic form of an
8614// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8615template<typename Derived>
8616ExprResult
8617TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8618 DesignatedInitUpdateExpr *E) {
8619 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8620 "initializer");
8621 return ExprError();
8622}
8623
8624template<typename Derived>
8625ExprResult
8626TreeTransform<Derived>::TransformNoInitExpr(
8627 NoInitExpr *E) {
8628 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8629 return ExprError();
8630}
8631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008633ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008634TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008635 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008636 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008637
Douglas Gregor3da3c062009-10-28 00:29:27 +00008638 // FIXME: Will we ever have proper type location here? Will we actually
8639 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008640 QualType T = getDerived().TransformType(E->getType());
8641 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008642 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008643
Douglas Gregora16548e2009-08-11 05:31:07 +00008644 if (!getDerived().AlwaysRebuild() &&
8645 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008646 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008647
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 return getDerived().RebuildImplicitValueInitExpr(T);
8649}
Mike Stump11289f42009-09-09 15:08:12 +00008650
Douglas Gregora16548e2009-08-11 05:31:07 +00008651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008653TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008654 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8655 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008657
John McCalldadc5752010-08-24 06:29:42 +00008658 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008661
Douglas Gregora16548e2009-08-11 05:31:07 +00008662 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008663 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008665 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008666
John McCallb268a282010-08-23 23:25:46 +00008667 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008668 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008669}
8670
8671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008673TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008674 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008675 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008676 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8677 &ArgumentChanged))
8678 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008679
Douglas Gregora16548e2009-08-11 05:31:07 +00008680 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008681 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 E->getRParenLoc());
8683}
Mike Stump11289f42009-09-09 15:08:12 +00008684
Douglas Gregora16548e2009-08-11 05:31:07 +00008685/// \brief Transform an address-of-label expression.
8686///
8687/// By default, the transformation of an address-of-label expression always
8688/// rebuilds the expression, so that the label identifier can be resolved to
8689/// the corresponding label statement by semantic analysis.
8690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008693 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8694 E->getLabel());
8695 if (!LD)
8696 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008697
Douglas Gregora16548e2009-08-11 05:31:07 +00008698 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008699 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008700}
Mike Stump11289f42009-09-09 15:08:12 +00008701
8702template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008704TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008705 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008706 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008707 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008708 if (SubStmt.isInvalid()) {
8709 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008710 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008711 }
Mike Stump11289f42009-09-09 15:08:12 +00008712
Douglas Gregora16548e2009-08-11 05:31:07 +00008713 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008714 SubStmt.get() == E->getSubStmt()) {
8715 // Calling this an 'error' is unintuitive, but it does the right thing.
8716 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008717 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008718 }
Mike Stump11289f42009-09-09 15:08:12 +00008719
8720 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008721 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008722 E->getRParenLoc());
8723}
Mike Stump11289f42009-09-09 15:08:12 +00008724
Douglas Gregora16548e2009-08-11 05:31:07 +00008725template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008726ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008727TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008728 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008729 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008731
John McCalldadc5752010-08-24 06:29:42 +00008732 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008733 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008735
John McCalldadc5752010-08-24 06:29:42 +00008736 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008737 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008739
Douglas Gregora16548e2009-08-11 05:31:07 +00008740 if (!getDerived().AlwaysRebuild() &&
8741 Cond.get() == E->getCond() &&
8742 LHS.get() == E->getLHS() &&
8743 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008744 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008745
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008747 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 E->getRParenLoc());
8749}
Mike Stump11289f42009-09-09 15:08:12 +00008750
Douglas Gregora16548e2009-08-11 05:31:07 +00008751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008753TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008754 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008755}
8756
8757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008758ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008759TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008760 switch (E->getOperator()) {
8761 case OO_New:
8762 case OO_Delete:
8763 case OO_Array_New:
8764 case OO_Array_Delete:
8765 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008766
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008767 case OO_Call: {
8768 // This is a call to an object's operator().
8769 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8770
8771 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008772 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008773 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008774 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008775
8776 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008777 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8778 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008779
8780 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008781 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008782 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008783 Args))
8784 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008785
John McCallb268a282010-08-23 23:25:46 +00008786 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008787 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008788 E->getLocEnd());
8789 }
8790
8791#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8792 case OO_##Name:
8793#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8794#include "clang/Basic/OperatorKinds.def"
8795 case OO_Subscript:
8796 // Handled below.
8797 break;
8798
8799 case OO_Conditional:
8800 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008801
8802 case OO_None:
8803 case NUM_OVERLOADED_OPERATORS:
8804 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008805 }
8806
John McCalldadc5752010-08-24 06:29:42 +00008807 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008810
Richard Smithdb2630f2012-10-21 03:28:35 +00008811 ExprResult First;
8812 if (E->getOperator() == OO_Amp)
8813 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8814 else
8815 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008816 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008817 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008818
John McCalldadc5752010-08-24 06:29:42 +00008819 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008820 if (E->getNumArgs() == 2) {
8821 Second = getDerived().TransformExpr(E->getArg(1));
8822 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008823 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008824 }
Mike Stump11289f42009-09-09 15:08:12 +00008825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 if (!getDerived().AlwaysRebuild() &&
8827 Callee.get() == E->getCallee() &&
8828 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008829 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008830 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008831
Lang Hames5de91cc2012-10-02 04:45:10 +00008832 Sema::FPContractStateRAII FPContractState(getSema());
8833 getSema().FPFeatures.fp_contract = E->isFPContractable();
8834
Douglas Gregora16548e2009-08-11 05:31:07 +00008835 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8836 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008837 Callee.get(),
8838 First.get(),
8839 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008840}
Mike Stump11289f42009-09-09 15:08:12 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008844TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8845 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008846}
Mike Stump11289f42009-09-09 15:08:12 +00008847
Douglas Gregora16548e2009-08-11 05:31:07 +00008848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008849ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008850TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8851 // Transform the callee.
8852 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8853 if (Callee.isInvalid())
8854 return ExprError();
8855
8856 // Transform exec config.
8857 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8858 if (EC.isInvalid())
8859 return ExprError();
8860
8861 // Transform arguments.
8862 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008863 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008864 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008865 &ArgChanged))
8866 return ExprError();
8867
8868 if (!getDerived().AlwaysRebuild() &&
8869 Callee.get() == E->getCallee() &&
8870 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008871 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008872
8873 // FIXME: Wrong source location information for the '('.
8874 SourceLocation FakeLParenLoc
8875 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8876 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008877 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008878 E->getRParenLoc(), EC.get());
8879}
8880
8881template<typename Derived>
8882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008883TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008884 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8885 if (!Type)
8886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008887
John McCalldadc5752010-08-24 06:29:42 +00008888 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008889 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008890 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008892
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008894 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008896 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008897 return getDerived().RebuildCXXNamedCastExpr(
8898 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8899 Type, E->getAngleBrackets().getEnd(),
8900 // FIXME. this should be '(' location
8901 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008902}
Mike Stump11289f42009-09-09 15:08:12 +00008903
Douglas Gregora16548e2009-08-11 05:31:07 +00008904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008906TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8907 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
8910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008912TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8913 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008914}
8915
Douglas Gregora16548e2009-08-11 05:31:07 +00008916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008917ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008918TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008919 CXXReinterpretCastExpr *E) {
8920 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008921}
Mike Stump11289f42009-09-09 15:08:12 +00008922
Douglas Gregora16548e2009-08-11 05:31:07 +00008923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008925TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8926 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008927}
Mike Stump11289f42009-09-09 15:08:12 +00008928
Douglas Gregora16548e2009-08-11 05:31:07 +00008929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008930ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008931TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008932 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008933 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8934 if (!Type)
8935 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008936
John McCalldadc5752010-08-24 06:29:42 +00008937 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008938 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008939 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008941
Douglas Gregora16548e2009-08-11 05:31:07 +00008942 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008943 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008945 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008946
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008947 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008948 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008949 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008950 E->getRParenLoc());
8951}
Mike Stump11289f42009-09-09 15:08:12 +00008952
Douglas Gregora16548e2009-08-11 05:31:07 +00008953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008955TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008957 TypeSourceInfo *TInfo
8958 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8959 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008961
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008963 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008964 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008965
Douglas Gregor9da64192010-04-26 22:37:10 +00008966 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8967 E->getLocStart(),
8968 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008969 E->getLocEnd());
8970 }
Mike Stump11289f42009-09-09 15:08:12 +00008971
Eli Friedman456f0182012-01-20 01:26:23 +00008972 // We don't know whether the subexpression is potentially evaluated until
8973 // after we perform semantic analysis. We speculatively assume it is
8974 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008975 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008976 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8977 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008978
John McCalldadc5752010-08-24 06:29:42 +00008979 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008980 if (SubExpr.isInvalid())
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 if (!getDerived().AlwaysRebuild() &&
8984 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008985 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008986
Douglas Gregor9da64192010-04-26 22:37:10 +00008987 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8988 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008989 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008990 E->getLocEnd());
8991}
8992
8993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008994ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008995TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8996 if (E->isTypeOperand()) {
8997 TypeSourceInfo *TInfo
8998 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8999 if (!TInfo)
9000 return ExprError();
9001
9002 if (!getDerived().AlwaysRebuild() &&
9003 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009004 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009005
Douglas Gregor69735112011-03-06 17:40:41 +00009006 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009007 E->getLocStart(),
9008 TInfo,
9009 E->getLocEnd());
9010 }
9011
Francois Pichet9f4f2072010-09-08 12:20:18 +00009012 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9013
9014 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9015 if (SubExpr.isInvalid())
9016 return ExprError();
9017
9018 if (!getDerived().AlwaysRebuild() &&
9019 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009020 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009021
9022 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9023 E->getLocStart(),
9024 SubExpr.get(),
9025 E->getLocEnd());
9026}
9027
9028template<typename Derived>
9029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009030TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009031 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009032}
Mike Stump11289f42009-09-09 15:08:12 +00009033
Douglas Gregora16548e2009-08-11 05:31:07 +00009034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009035ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009036TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009037 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009038 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009039}
Mike Stump11289f42009-09-09 15:08:12 +00009040
Douglas Gregora16548e2009-08-11 05:31:07 +00009041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009043TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009044 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009045
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009046 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9047 // Make sure that we capture 'this'.
9048 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009049 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009051
Douglas Gregorb15af892010-01-07 23:12:05 +00009052 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009053}
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009057TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009058 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009059 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009061
Douglas Gregora16548e2009-08-11 05:31:07 +00009062 if (!getDerived().AlwaysRebuild() &&
9063 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009064 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009065
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009066 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9067 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009068}
Mike Stump11289f42009-09-09 15:08:12 +00009069
Douglas Gregora16548e2009-08-11 05:31:07 +00009070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009072TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009073 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009074 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9075 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009076 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009078
Chandler Carruth794da4c2010-02-08 06:42:49 +00009079 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009080 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009081 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009082
Douglas Gregor033f6752009-12-23 23:03:06 +00009083 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009084}
Mike Stump11289f42009-09-09 15:08:12 +00009085
Douglas Gregora16548e2009-08-11 05:31:07 +00009086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009087ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009088TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9089 FieldDecl *Field
9090 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9091 E->getField()));
9092 if (!Field)
9093 return ExprError();
9094
9095 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009096 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009097
9098 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9099}
9100
9101template<typename Derived>
9102ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009103TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9104 CXXScalarValueInitExpr *E) {
9105 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9106 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009107 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregora16548e2009-08-11 05:31:07 +00009109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009110 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009111 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009112
Chad Rosier1dcde962012-08-08 18:46:20 +00009113 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009114 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009115 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009116}
Mike Stump11289f42009-09-09 15:08:12 +00009117
Douglas Gregora16548e2009-08-11 05:31:07 +00009118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009120TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009121 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009122 TypeSourceInfo *AllocTypeInfo
9123 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9124 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009126
Douglas Gregora16548e2009-08-11 05:31:07 +00009127 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009128 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009129 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009131
Douglas Gregora16548e2009-08-11 05:31:07 +00009132 // Transform the placement arguments (if any).
9133 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009134 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009135 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009136 E->getNumPlacementArgs(), true,
9137 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009139
Sebastian Redl6047f072012-02-16 12:22:20 +00009140 // Transform the initializer (if any).
9141 Expr *OldInit = E->getInitializer();
9142 ExprResult NewInit;
9143 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009144 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009145 if (NewInit.isInvalid())
9146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009147
Sebastian Redl6047f072012-02-16 12:22:20 +00009148 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009149 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009150 if (E->getOperatorNew()) {
9151 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009152 getDerived().TransformDecl(E->getLocStart(),
9153 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009154 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009155 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009156 }
9157
Craig Topperc3ec1492014-05-26 06:22:03 +00009158 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009159 if (E->getOperatorDelete()) {
9160 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009161 getDerived().TransformDecl(E->getLocStart(),
9162 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009163 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009164 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009166
Douglas Gregora16548e2009-08-11 05:31:07 +00009167 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009168 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009170 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009171 OperatorNew == E->getOperatorNew() &&
9172 OperatorDelete == E->getOperatorDelete() &&
9173 !ArgumentChanged) {
9174 // Mark any declarations we need as referenced.
9175 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009176 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009177 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009178 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009179 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009180
Sebastian Redl6047f072012-02-16 12:22:20 +00009181 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009182 QualType ElementType
9183 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9184 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9185 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9186 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009187 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009188 }
9189 }
9190 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009191
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009192 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009193 }
Mike Stump11289f42009-09-09 15:08:12 +00009194
Douglas Gregor0744ef62010-09-07 21:49:58 +00009195 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009196 if (!ArraySize.get()) {
9197 // If no array size was specified, but the new expression was
9198 // instantiated with an array type (e.g., "new T" where T is
9199 // instantiated with "int[4]"), extract the outer bound from the
9200 // array type as our array size. We do this with constant and
9201 // dependently-sized array types.
9202 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9203 if (!ArrayT) {
9204 // Do nothing
9205 } else if (const ConstantArrayType *ConsArrayT
9206 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009207 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9208 SemaRef.Context.getSizeType(),
9209 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009210 AllocType = ConsArrayT->getElementType();
9211 } else if (const DependentSizedArrayType *DepArrayT
9212 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9213 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009214 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009215 AllocType = DepArrayT->getElementType();
9216 }
9217 }
9218 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009219
Douglas Gregora16548e2009-08-11 05:31:07 +00009220 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9221 E->isGlobalNew(),
9222 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009223 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009224 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009225 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009226 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009227 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009228 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009229 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009230 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
Mike Stump11289f42009-09-09 15:08:12 +00009232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009236 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009237 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009239
Douglas Gregord2d9da02010-02-26 00:38:10 +00009240 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009241 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009242 if (E->getOperatorDelete()) {
9243 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009244 getDerived().TransformDecl(E->getLocStart(),
9245 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009246 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009247 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009249
Douglas Gregora16548e2009-08-11 05:31:07 +00009250 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009251 Operand.get() == E->getArgument() &&
9252 OperatorDelete == E->getOperatorDelete()) {
9253 // Mark any declarations we need as referenced.
9254 // FIXME: instantiation-specific.
9255 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009256 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009257
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009258 if (!E->getArgument()->isTypeDependent()) {
9259 QualType Destroyed = SemaRef.Context.getBaseElementType(
9260 E->getDestroyedType());
9261 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9262 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009263 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009264 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009265 }
9266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009267
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009268 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009269 }
Mike Stump11289f42009-09-09 15:08:12 +00009270
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9272 E->isGlobalDelete(),
9273 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009274 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009275}
Mike Stump11289f42009-09-09 15:08:12 +00009276
Douglas Gregora16548e2009-08-11 05:31:07 +00009277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009278ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009279TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009280 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009281 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009282 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009284
John McCallba7bf592010-08-24 05:47:05 +00009285 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009286 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009287 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009288 E->getOperatorLoc(),
9289 E->isArrow()? tok::arrow : tok::period,
9290 ObjectTypePtr,
9291 MayBePseudoDestructor);
9292 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009293 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009294
John McCallba7bf592010-08-24 05:47:05 +00009295 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009296 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9297 if (QualifierLoc) {
9298 QualifierLoc
9299 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9300 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009301 return ExprError();
9302 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009303 CXXScopeSpec SS;
9304 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009305
Douglas Gregor678f90d2010-02-25 01:56:36 +00009306 PseudoDestructorTypeStorage Destroyed;
9307 if (E->getDestroyedTypeInfo()) {
9308 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009309 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009310 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009311 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009312 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009313 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009314 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009315 // We aren't likely to be able to resolve the identifier down to a type
9316 // now anyway, so just retain the identifier.
9317 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9318 E->getDestroyedTypeLoc());
9319 } else {
9320 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009321 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009322 *E->getDestroyedTypeIdentifier(),
9323 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009324 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009325 SS, ObjectTypePtr,
9326 false);
9327 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009329
Douglas Gregor678f90d2010-02-25 01:56:36 +00009330 Destroyed
9331 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9332 E->getDestroyedTypeLoc());
9333 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009334
Craig Topperc3ec1492014-05-26 06:22:03 +00009335 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009336 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009337 CXXScopeSpec EmptySS;
9338 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009339 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009340 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009341 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009343
John McCallb268a282010-08-23 23:25:46 +00009344 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009345 E->getOperatorLoc(),
9346 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009347 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009348 ScopeTypeInfo,
9349 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009350 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009351 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009352}
Mike Stump11289f42009-09-09 15:08:12 +00009353
Douglas Gregorad8a3362009-09-04 17:36:40 +00009354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009355ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009356TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009357 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009358 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9359 Sema::LookupOrdinaryName);
9360
9361 // Transform all the decls.
9362 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9363 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009364 NamedDecl *InstD = static_cast<NamedDecl*>(
9365 getDerived().TransformDecl(Old->getNameLoc(),
9366 *I));
John McCall84d87672009-12-10 09:41:52 +00009367 if (!InstD) {
9368 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9369 // This can happen because of dependent hiding.
9370 if (isa<UsingShadowDecl>(*I))
9371 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009372 else {
9373 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009374 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009375 }
John McCall84d87672009-12-10 09:41:52 +00009376 }
John McCalle66edc12009-11-24 19:00:30 +00009377
9378 // Expand using declarations.
9379 if (isa<UsingDecl>(InstD)) {
9380 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009381 for (auto *I : UD->shadows())
9382 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009383 continue;
9384 }
9385
9386 R.addDecl(InstD);
9387 }
9388
9389 // Resolve a kind, but don't do any further analysis. If it's
9390 // ambiguous, the callee needs to deal with it.
9391 R.resolveKind();
9392
9393 // Rebuild the nested-name qualifier, if present.
9394 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009395 if (Old->getQualifierLoc()) {
9396 NestedNameSpecifierLoc QualifierLoc
9397 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9398 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009399 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009400
Douglas Gregor0da1d432011-02-28 20:01:57 +00009401 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009402 }
9403
Douglas Gregor9262f472010-04-27 18:19:34 +00009404 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009405 CXXRecordDecl *NamingClass
9406 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9407 Old->getNameLoc(),
9408 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009409 if (!NamingClass) {
9410 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009411 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009412 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009413
Douglas Gregorda7be082010-04-27 16:10:10 +00009414 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009415 }
9416
Abramo Bagnara7945c982012-01-27 09:46:47 +00009417 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9418
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009419 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009420 // it's a normal declaration name or member reference.
9421 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9422 NamedDecl *D = R.getAsSingle<NamedDecl>();
9423 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9424 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9425 // give a good diagnostic.
9426 if (D && D->isCXXInstanceMember()) {
9427 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9428 /*TemplateArgs=*/nullptr,
9429 /*Scope=*/nullptr);
9430 }
9431
John McCalle66edc12009-11-24 19:00:30 +00009432 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009433 }
John McCalle66edc12009-11-24 19:00:30 +00009434
9435 // If we have template arguments, rebuild them, then rebuild the
9436 // templateid expression.
9437 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009438 if (Old->hasExplicitTemplateArgs() &&
9439 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009440 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009441 TransArgs)) {
9442 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009443 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009444 }
John McCalle66edc12009-11-24 19:00:30 +00009445
Abramo Bagnara7945c982012-01-27 09:46:47 +00009446 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009447 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009448}
Mike Stump11289f42009-09-09 15:08:12 +00009449
Douglas Gregora16548e2009-08-11 05:31:07 +00009450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009451ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009452TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9453 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009454 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009455 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9456 TypeSourceInfo *From = E->getArg(I);
9457 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009458 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009459 TypeLocBuilder TLB;
9460 TLB.reserve(FromTL.getFullDataSize());
9461 QualType To = getDerived().TransformType(TLB, FromTL);
9462 if (To.isNull())
9463 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009464
Douglas Gregor29c42f22012-02-24 07:38:34 +00009465 if (To == From->getType())
9466 Args.push_back(From);
9467 else {
9468 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9469 ArgChanged = true;
9470 }
9471 continue;
9472 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009473
Douglas Gregor29c42f22012-02-24 07:38:34 +00009474 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009475
Douglas Gregor29c42f22012-02-24 07:38:34 +00009476 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009477 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009478 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9479 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9480 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009481
Douglas Gregor29c42f22012-02-24 07:38:34 +00009482 // Determine whether the set of unexpanded parameter packs can and should
9483 // be expanded.
9484 bool Expand = true;
9485 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009486 Optional<unsigned> OrigNumExpansions =
9487 ExpansionTL.getTypePtr()->getNumExpansions();
9488 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009489 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9490 PatternTL.getSourceRange(),
9491 Unexpanded,
9492 Expand, RetainExpansion,
9493 NumExpansions))
9494 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009495
Douglas Gregor29c42f22012-02-24 07:38:34 +00009496 if (!Expand) {
9497 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009498 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009499 // expansion.
9500 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009501
Douglas Gregor29c42f22012-02-24 07:38:34 +00009502 TypeLocBuilder TLB;
9503 TLB.reserve(From->getTypeLoc().getFullDataSize());
9504
9505 QualType To = getDerived().TransformType(TLB, PatternTL);
9506 if (To.isNull())
9507 return ExprError();
9508
Chad Rosier1dcde962012-08-08 18:46:20 +00009509 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009510 PatternTL.getSourceRange(),
9511 ExpansionTL.getEllipsisLoc(),
9512 NumExpansions);
9513 if (To.isNull())
9514 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009515
Douglas Gregor29c42f22012-02-24 07:38:34 +00009516 PackExpansionTypeLoc ToExpansionTL
9517 = TLB.push<PackExpansionTypeLoc>(To);
9518 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9519 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9520 continue;
9521 }
9522
9523 // Expand the pack expansion by substituting for each argument in the
9524 // pack(s).
9525 for (unsigned I = 0; I != *NumExpansions; ++I) {
9526 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9527 TypeLocBuilder TLB;
9528 TLB.reserve(PatternTL.getFullDataSize());
9529 QualType To = getDerived().TransformType(TLB, PatternTL);
9530 if (To.isNull())
9531 return ExprError();
9532
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009533 if (To->containsUnexpandedParameterPack()) {
9534 To = getDerived().RebuildPackExpansionType(To,
9535 PatternTL.getSourceRange(),
9536 ExpansionTL.getEllipsisLoc(),
9537 NumExpansions);
9538 if (To.isNull())
9539 return ExprError();
9540
9541 PackExpansionTypeLoc ToExpansionTL
9542 = TLB.push<PackExpansionTypeLoc>(To);
9543 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9544 }
9545
Douglas Gregor29c42f22012-02-24 07:38:34 +00009546 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009548
Douglas Gregor29c42f22012-02-24 07:38:34 +00009549 if (!RetainExpansion)
9550 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009551
Douglas Gregor29c42f22012-02-24 07:38:34 +00009552 // If we're supposed to retain a pack expansion, do so by temporarily
9553 // forgetting the partially-substituted parameter pack.
9554 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9555
9556 TypeLocBuilder TLB;
9557 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009558
Douglas Gregor29c42f22012-02-24 07:38:34 +00009559 QualType To = getDerived().TransformType(TLB, PatternTL);
9560 if (To.isNull())
9561 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009562
9563 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009564 PatternTL.getSourceRange(),
9565 ExpansionTL.getEllipsisLoc(),
9566 NumExpansions);
9567 if (To.isNull())
9568 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009569
Douglas Gregor29c42f22012-02-24 07:38:34 +00009570 PackExpansionTypeLoc ToExpansionTL
9571 = TLB.push<PackExpansionTypeLoc>(To);
9572 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9573 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009575
Douglas Gregor29c42f22012-02-24 07:38:34 +00009576 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009577 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009578
9579 return getDerived().RebuildTypeTrait(E->getTrait(),
9580 E->getLocStart(),
9581 Args,
9582 E->getLocEnd());
9583}
9584
9585template<typename Derived>
9586ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009587TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9588 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9589 if (!T)
9590 return ExprError();
9591
9592 if (!getDerived().AlwaysRebuild() &&
9593 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009594 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009595
9596 ExprResult SubExpr;
9597 {
9598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9599 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9600 if (SubExpr.isInvalid())
9601 return ExprError();
9602
9603 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009604 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009605 }
9606
9607 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9608 E->getLocStart(),
9609 T,
9610 SubExpr.get(),
9611 E->getLocEnd());
9612}
9613
9614template<typename Derived>
9615ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009616TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9617 ExprResult SubExpr;
9618 {
9619 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9620 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9621 if (SubExpr.isInvalid())
9622 return ExprError();
9623
9624 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009625 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009626 }
9627
9628 return getDerived().RebuildExpressionTrait(
9629 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9630}
9631
Reid Kleckner32506ed2014-06-12 23:03:48 +00009632template <typename Derived>
9633ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9634 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9635 TypeSourceInfo **RecoveryTSI) {
9636 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9637 DRE, AddrTaken, RecoveryTSI);
9638
9639 // Propagate both errors and recovered types, which return ExprEmpty.
9640 if (!NewDRE.isUsable())
9641 return NewDRE;
9642
9643 // We got an expr, wrap it up in parens.
9644 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9645 return PE;
9646 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9647 PE->getRParen());
9648}
9649
9650template <typename Derived>
9651ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9652 DependentScopeDeclRefExpr *E) {
9653 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9654 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009655}
9656
9657template<typename Derived>
9658ExprResult
9659TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9660 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009661 bool IsAddressOfOperand,
9662 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009663 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009664 NestedNameSpecifierLoc QualifierLoc
9665 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9666 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009667 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009668 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009669
John McCall31f82722010-11-12 08:19:04 +00009670 // TODO: If this is a conversion-function-id, verify that the
9671 // destination type name (if present) resolves the same way after
9672 // instantiation as it did in the local scope.
9673
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009674 DeclarationNameInfo NameInfo
9675 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9676 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009678
John McCalle66edc12009-11-24 19:00:30 +00009679 if (!E->hasExplicitTemplateArgs()) {
9680 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009681 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009682 // Note: it is sufficient to compare the Name component of NameInfo:
9683 // if name has not changed, DNLoc has not changed either.
9684 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009685 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009686
Reid Kleckner32506ed2014-06-12 23:03:48 +00009687 return getDerived().RebuildDependentScopeDeclRefExpr(
9688 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9689 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009690 }
John McCall6b51f282009-11-23 01:53:49 +00009691
9692 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009693 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9694 E->getNumTemplateArgs(),
9695 TransArgs))
9696 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009697
Reid Kleckner32506ed2014-06-12 23:03:48 +00009698 return getDerived().RebuildDependentScopeDeclRefExpr(
9699 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9700 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009701}
9702
9703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009705TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009706 // CXXConstructExprs other than for list-initialization and
9707 // CXXTemporaryObjectExpr are always implicit, so when we have
9708 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009709 if ((E->getNumArgs() == 1 ||
9710 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009711 (!getDerived().DropCallArgument(E->getArg(0))) &&
9712 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009713 return getDerived().TransformExpr(E->getArg(0));
9714
Douglas Gregora16548e2009-08-11 05:31:07 +00009715 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9716
9717 QualType T = getDerived().TransformType(E->getType());
9718 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009719 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009720
9721 CXXConstructorDecl *Constructor
9722 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009723 getDerived().TransformDecl(E->getLocStart(),
9724 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009725 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregora16548e2009-08-11 05:31:07 +00009728 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009729 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009730 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009731 &ArgumentChanged))
9732 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009733
Douglas Gregora16548e2009-08-11 05:31:07 +00009734 if (!getDerived().AlwaysRebuild() &&
9735 T == E->getType() &&
9736 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009737 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009738 // Mark the constructor as referenced.
9739 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009740 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009741 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009742 }
Mike Stump11289f42009-09-09 15:08:12 +00009743
Douglas Gregordb121ba2009-12-14 16:27:04 +00009744 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9745 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009746 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009747 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009748 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009749 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009750 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009751 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009752 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009753}
Mike Stump11289f42009-09-09 15:08:12 +00009754
Douglas Gregora16548e2009-08-11 05:31:07 +00009755/// \brief Transform a C++ temporary-binding expression.
9756///
Douglas Gregor363b1512009-12-24 18:51:59 +00009757/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9758/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009761TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009762 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009763}
Mike Stump11289f42009-09-09 15:08:12 +00009764
John McCall5d413782010-12-06 08:20:24 +00009765/// \brief Transform a C++ expression that contains cleanups that should
9766/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009767///
John McCall5d413782010-12-06 08:20:24 +00009768/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009769/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009771ExprResult
John McCall5d413782010-12-06 08:20:24 +00009772TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009773 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009774}
Mike Stump11289f42009-09-09 15:08:12 +00009775
Douglas Gregora16548e2009-08-11 05:31:07 +00009776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009777ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009778TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009779 CXXTemporaryObjectExpr *E) {
9780 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9781 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009783
Douglas Gregora16548e2009-08-11 05:31:07 +00009784 CXXConstructorDecl *Constructor
9785 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009786 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009787 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009790
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009792 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009793 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009794 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009795 &ArgumentChanged))
9796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009797
Douglas Gregora16548e2009-08-11 05:31:07 +00009798 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009799 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009801 !ArgumentChanged) {
9802 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009803 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009804 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009806
Richard Smithd59b8322012-12-19 01:39:02 +00009807 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009808 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9809 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009810 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 E->getLocEnd());
9812}
Mike Stump11289f42009-09-09 15:08:12 +00009813
Douglas Gregora16548e2009-08-11 05:31:07 +00009814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009815ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009816TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009817 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009818 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009819 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009820 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9821 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009822 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009823 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009824 CEnd = E->capture_end();
9825 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009826 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009827 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009828 EnterExpressionEvaluationContext EEEC(getSema(),
9829 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009830 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9831 C->getCapturedVar()->getInit(),
9832 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009833
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009834 if (NewExprInitResult.isInvalid())
9835 return ExprError();
9836 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009837
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009838 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009839 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009840 getSema().buildLambdaInitCaptureInitialization(
9841 C->getLocation(), OldVD->getType()->isReferenceType(),
9842 OldVD->getIdentifier(),
9843 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009844 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009845 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9846 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009847 }
9848
Faisal Vali2cba1332013-10-23 06:44:28 +00009849 // Transform the template parameters, and add them to the current
9850 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009851 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009852 E->getTemplateParameterList());
9853
Richard Smith01014ce2014-11-20 23:53:14 +00009854 // Transform the type of the original lambda's call operator.
9855 // The transformation MUST be done in the CurrentInstantiationScope since
9856 // it introduces a mapping of the original to the newly created
9857 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009858 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009859 {
9860 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9861 FunctionProtoTypeLoc OldCallOpFPTL =
9862 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009863
9864 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009865 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009866 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009867 QualType NewCallOpType = TransformFunctionProtoType(
9868 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009869 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9870 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9871 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009872 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009873 if (NewCallOpType.isNull())
9874 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009875 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9876 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009877 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009878
Richard Smithc38498f2015-04-27 21:27:54 +00009879 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9880 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9881 LSI->GLTemplateParameterList = TPL;
9882
Eli Friedmand564afb2012-09-19 01:18:11 +00009883 // Create the local class that will describe the lambda.
9884 CXXRecordDecl *Class
9885 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009886 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009887 /*KnownDependent=*/false,
9888 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009889 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9890
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009891 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009892 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9893 Class, E->getIntroducerRange(), NewCallOpTSI,
9894 E->getCallOperator()->getLocEnd(),
9895 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009896 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009897
Faisal Vali2cba1332013-10-23 06:44:28 +00009898 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009899 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009900
Douglas Gregorb4328232012-02-14 00:00:48 +00009901 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009902 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009903 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009904
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009905 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009906 getSema().buildLambdaScope(LSI, NewCallOperator,
9907 E->getIntroducerRange(),
9908 E->getCaptureDefault(),
9909 E->getCaptureDefaultLoc(),
9910 E->hasExplicitParameters(),
9911 E->hasExplicitResultType(),
9912 E->isMutable());
9913
9914 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009915
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009916 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009917 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009918 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009919 CEnd = E->capture_end();
9920 C != CEnd; ++C) {
9921 // When we hit the first implicit capture, tell Sema that we've finished
9922 // the list of explicit captures.
9923 if (!FinishedExplicitCaptures && C->isImplicit()) {
9924 getSema().finishLambdaExplicitCaptures(LSI);
9925 FinishedExplicitCaptures = true;
9926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009927
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009928 // Capturing 'this' is trivial.
9929 if (C->capturesThis()) {
9930 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9931 continue;
9932 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009933 // Captured expression will be recaptured during captured variables
9934 // rebuilding.
9935 if (C->capturesVLAType())
9936 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009937
Richard Smithba71c082013-05-16 06:20:58 +00009938 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009939 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009940 InitCaptureInfoTy InitExprTypePair =
9941 InitCaptureExprsAndTypes[C - E->capture_begin()];
9942 ExprResult Init = InitExprTypePair.first;
9943 QualType InitQualType = InitExprTypePair.second;
9944 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009945 Invalid = true;
9946 continue;
9947 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009948 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009949 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +00009950 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9951 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009952 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009953 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009954 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009955 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009956 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009957 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009958 continue;
9959 }
9960
9961 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9962
Douglas Gregor3e308b12012-02-14 19:27:52 +00009963 // Determine the capture kind for Sema.
9964 Sema::TryCaptureKind Kind
9965 = C->isImplicit()? Sema::TryCapture_Implicit
9966 : C->getCaptureKind() == LCK_ByCopy
9967 ? Sema::TryCapture_ExplicitByVal
9968 : Sema::TryCapture_ExplicitByRef;
9969 SourceLocation EllipsisLoc;
9970 if (C->isPackExpansion()) {
9971 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9972 bool ShouldExpand = false;
9973 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009974 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009975 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9976 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009977 Unexpanded,
9978 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009979 NumExpansions)) {
9980 Invalid = true;
9981 continue;
9982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009983
Douglas Gregor3e308b12012-02-14 19:27:52 +00009984 if (ShouldExpand) {
9985 // The transform has determined that we should perform an expansion;
9986 // transform and capture each of the arguments.
9987 // expansion of the pattern. Do so.
9988 VarDecl *Pack = C->getCapturedVar();
9989 for (unsigned I = 0; I != *NumExpansions; ++I) {
9990 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9991 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009992 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009993 Pack));
9994 if (!CapturedVar) {
9995 Invalid = true;
9996 continue;
9997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009998
Douglas Gregor3e308b12012-02-14 19:27:52 +00009999 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010000 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10001 }
Richard Smith9467be42014-06-06 17:33:35 +000010002
10003 // FIXME: Retain a pack expansion if RetainExpansion is true.
10004
Douglas Gregor3e308b12012-02-14 19:27:52 +000010005 continue;
10006 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010007
Douglas Gregor3e308b12012-02-14 19:27:52 +000010008 EllipsisLoc = C->getEllipsisLoc();
10009 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010010
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010011 // Transform the captured variable.
10012 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010013 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010014 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010015 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010016 Invalid = true;
10017 continue;
10018 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010019
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010020 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010021 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10022 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010023 }
10024 if (!FinishedExplicitCaptures)
10025 getSema().finishLambdaExplicitCaptures(LSI);
10026
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010027 // Enter a new evaluation context to insulate the lambda from any
10028 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010029 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010030
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010031 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010032 StmtResult Body =
10033 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10034
10035 // ActOnLambda* will pop the function scope for us.
10036 FuncScopeCleanup.disable();
10037
Douglas Gregorb4328232012-02-14 00:00:48 +000010038 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010039 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010040 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010041 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010042 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010043 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010044
Richard Smithc38498f2015-04-27 21:27:54 +000010045 // Copy the LSI before ActOnFinishFunctionBody removes it.
10046 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10047 // the call operator.
10048 auto LSICopy = *LSI;
10049 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10050 /*IsInstantiation*/ true);
10051 SavedContext.pop();
10052
10053 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10054 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010055}
10056
10057template<typename Derived>
10058ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010059TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010060 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010061 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10062 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010063 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010064
Douglas Gregora16548e2009-08-11 05:31:07 +000010065 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010066 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010067 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010068 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010069 &ArgumentChanged))
10070 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010071
Douglas Gregora16548e2009-08-11 05:31:07 +000010072 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010073 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010074 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010075 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregora16548e2009-08-11 05:31:07 +000010077 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010078 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010079 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010080 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010081 E->getRParenLoc());
10082}
Mike Stump11289f42009-09-09 15:08:12 +000010083
Douglas Gregora16548e2009-08-11 05:31:07 +000010084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010085ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010086TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010087 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010088 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010089 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010090 Expr *OldBase;
10091 QualType BaseType;
10092 QualType ObjectType;
10093 if (!E->isImplicitAccess()) {
10094 OldBase = E->getBase();
10095 Base = getDerived().TransformExpr(OldBase);
10096 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010098
John McCall2d74de92009-12-01 22:10:20 +000010099 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010100 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010101 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010102 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010103 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010104 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010105 ObjectTy,
10106 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010107 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010108 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010109
John McCallba7bf592010-08-24 05:47:05 +000010110 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010111 BaseType = ((Expr*) Base.get())->getType();
10112 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010113 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010114 BaseType = getDerived().TransformType(E->getBaseType());
10115 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10116 }
Mike Stump11289f42009-09-09 15:08:12 +000010117
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010118 // Transform the first part of the nested-name-specifier that qualifies
10119 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010120 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010121 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010122 E->getFirstQualifierFoundInScope(),
10123 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010124
Douglas Gregore16af532011-02-28 18:50:33 +000010125 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010126 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010127 QualifierLoc
10128 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10129 ObjectType,
10130 FirstQualifierInScope);
10131 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010132 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010133 }
Mike Stump11289f42009-09-09 15:08:12 +000010134
Abramo Bagnara7945c982012-01-27 09:46:47 +000010135 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10136
John McCall31f82722010-11-12 08:19:04 +000010137 // TODO: If this is a conversion-function-id, verify that the
10138 // destination type name (if present) resolves the same way after
10139 // instantiation as it did in the local scope.
10140
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010141 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010142 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010143 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010144 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010145
John McCall2d74de92009-12-01 22:10:20 +000010146 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010147 // This is a reference to a member without an explicitly-specified
10148 // template argument list. Optimize for this common case.
10149 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010150 Base.get() == OldBase &&
10151 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010152 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010153 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010154 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010155 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010156
John McCallb268a282010-08-23 23:25:46 +000010157 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010158 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010159 E->isArrow(),
10160 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010161 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010162 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010163 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010164 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010165 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010166 }
10167
John McCall6b51f282009-11-23 01:53:49 +000010168 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010169 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10170 E->getNumTemplateArgs(),
10171 TransArgs))
10172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010173
John McCallb268a282010-08-23 23:25:46 +000010174 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010175 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010176 E->isArrow(),
10177 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010178 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010179 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010180 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010181 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010182 &TransArgs);
10183}
10184
10185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010187TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010188 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010189 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010190 QualType BaseType;
10191 if (!Old->isImplicitAccess()) {
10192 Base = getDerived().TransformExpr(Old->getBase());
10193 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010194 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010195 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010196 Old->isArrow());
10197 if (Base.isInvalid())
10198 return ExprError();
10199 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010200 } else {
10201 BaseType = getDerived().TransformType(Old->getBaseType());
10202 }
John McCall10eae182009-11-30 22:42:35 +000010203
Douglas Gregor0da1d432011-02-28 20:01:57 +000010204 NestedNameSpecifierLoc QualifierLoc;
10205 if (Old->getQualifierLoc()) {
10206 QualifierLoc
10207 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10208 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010209 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010210 }
10211
Abramo Bagnara7945c982012-01-27 09:46:47 +000010212 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10213
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010214 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010215 Sema::LookupOrdinaryName);
10216
10217 // Transform all the decls.
10218 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10219 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010220 NamedDecl *InstD = static_cast<NamedDecl*>(
10221 getDerived().TransformDecl(Old->getMemberLoc(),
10222 *I));
John McCall84d87672009-12-10 09:41:52 +000010223 if (!InstD) {
10224 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10225 // This can happen because of dependent hiding.
10226 if (isa<UsingShadowDecl>(*I))
10227 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010228 else {
10229 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010230 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010231 }
John McCall84d87672009-12-10 09:41:52 +000010232 }
John McCall10eae182009-11-30 22:42:35 +000010233
10234 // Expand using declarations.
10235 if (isa<UsingDecl>(InstD)) {
10236 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010237 for (auto *I : UD->shadows())
10238 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010239 continue;
10240 }
10241
10242 R.addDecl(InstD);
10243 }
10244
10245 R.resolveKind();
10246
Douglas Gregor9262f472010-04-27 18:19:34 +000010247 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010248 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010249 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010250 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010251 Old->getMemberLoc(),
10252 Old->getNamingClass()));
10253 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010254 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010255
Douglas Gregorda7be082010-04-27 16:10:10 +000010256 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010257 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010258
John McCall10eae182009-11-30 22:42:35 +000010259 TemplateArgumentListInfo TransArgs;
10260 if (Old->hasExplicitTemplateArgs()) {
10261 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10262 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010263 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10264 Old->getNumTemplateArgs(),
10265 TransArgs))
10266 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010267 }
John McCall38836f02010-01-15 08:34:02 +000010268
10269 // FIXME: to do this check properly, we will need to preserve the
10270 // first-qualifier-in-scope here, just in case we had a dependent
10271 // base (and therefore couldn't do the check) and a
10272 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010273 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010274
John McCallb268a282010-08-23 23:25:46 +000010275 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010276 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010277 Old->getOperatorLoc(),
10278 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010279 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010280 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010281 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010282 R,
10283 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010284 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010285}
10286
10287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010288ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010289TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010290 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010291 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10292 if (SubExpr.isInvalid())
10293 return ExprError();
10294
10295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010296 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010297
10298 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10299}
10300
10301template<typename Derived>
10302ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010303TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010304 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10305 if (Pattern.isInvalid())
10306 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010307
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010308 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010309 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010310
Douglas Gregorb8840002011-01-14 21:20:45 +000010311 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10312 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010313}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010314
10315template<typename Derived>
10316ExprResult
10317TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10318 // If E is not value-dependent, then nothing will change when we transform it.
10319 // Note: This is an instantiation-centric view.
10320 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010321 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010322
Richard Smithd784e682015-09-23 21:41:42 +000010323 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010324
Richard Smithd784e682015-09-23 21:41:42 +000010325 ArrayRef<TemplateArgument> PackArgs;
10326 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010327
Richard Smithd784e682015-09-23 21:41:42 +000010328 // Find the argument list to transform.
10329 if (E->isPartiallySubstituted()) {
10330 PackArgs = E->getPartialArguments();
10331 } else if (E->isValueDependent()) {
10332 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10333 bool ShouldExpand = false;
10334 bool RetainExpansion = false;
10335 Optional<unsigned> NumExpansions;
10336 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10337 Unexpanded,
10338 ShouldExpand, RetainExpansion,
10339 NumExpansions))
10340 return ExprError();
10341
10342 // If we need to expand the pack, build a template argument from it and
10343 // expand that.
10344 if (ShouldExpand) {
10345 auto *Pack = E->getPack();
10346 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10347 ArgStorage = getSema().Context.getPackExpansionType(
10348 getSema().Context.getTypeDeclType(TTPD), None);
10349 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10350 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10351 } else {
10352 auto *VD = cast<ValueDecl>(Pack);
10353 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10354 VK_RValue, E->getPackLoc());
10355 if (DRE.isInvalid())
10356 return ExprError();
10357 ArgStorage = new (getSema().Context) PackExpansionExpr(
10358 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10359 }
10360 PackArgs = ArgStorage;
10361 }
10362 }
10363
10364 // If we're not expanding the pack, just transform the decl.
10365 if (!PackArgs.size()) {
10366 auto *Pack = cast_or_null<NamedDecl>(
10367 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010368 if (!Pack)
10369 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010370 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10371 E->getPackLoc(),
10372 E->getRParenLoc(), None, None);
10373 }
10374
10375 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10376 E->getPackLoc());
10377 {
10378 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10379 typedef TemplateArgumentLocInventIterator<
10380 Derived, const TemplateArgument*> PackLocIterator;
10381 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10382 PackLocIterator(*this, PackArgs.end()),
10383 TransformedPackArgs, /*Uneval*/true))
10384 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010385 }
10386
Richard Smithd784e682015-09-23 21:41:42 +000010387 SmallVector<TemplateArgument, 8> Args;
10388 bool PartialSubstitution = false;
10389 for (auto &Loc : TransformedPackArgs.arguments()) {
10390 Args.push_back(Loc.getArgument());
10391 if (Loc.getArgument().isPackExpansion())
10392 PartialSubstitution = true;
10393 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010394
Richard Smithd784e682015-09-23 21:41:42 +000010395 if (PartialSubstitution)
10396 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10397 E->getPackLoc(),
10398 E->getRParenLoc(), None, Args);
10399
10400 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010401 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010402 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010403}
10404
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010405template<typename Derived>
10406ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010407TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10408 SubstNonTypeTemplateParmPackExpr *E) {
10409 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010410 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010411}
10412
10413template<typename Derived>
10414ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010415TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10416 SubstNonTypeTemplateParmExpr *E) {
10417 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010418 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010419}
10420
10421template<typename Derived>
10422ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010423TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10424 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010425 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010426}
10427
10428template<typename Derived>
10429ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010430TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10431 MaterializeTemporaryExpr *E) {
10432 return getDerived().TransformExpr(E->GetTemporaryExpr());
10433}
Chad Rosier1dcde962012-08-08 18:46:20 +000010434
Douglas Gregorfe314812011-06-21 17:03:29 +000010435template<typename Derived>
10436ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010437TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10438 Expr *Pattern = E->getPattern();
10439
10440 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10441 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10442 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10443
10444 // Determine whether the set of unexpanded parameter packs can and should
10445 // be expanded.
10446 bool Expand = true;
10447 bool RetainExpansion = false;
10448 Optional<unsigned> NumExpansions;
10449 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10450 Pattern->getSourceRange(),
10451 Unexpanded,
10452 Expand, RetainExpansion,
10453 NumExpansions))
10454 return true;
10455
10456 if (!Expand) {
10457 // Do not expand any packs here, just transform and rebuild a fold
10458 // expression.
10459 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10460
10461 ExprResult LHS =
10462 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10463 if (LHS.isInvalid())
10464 return true;
10465
10466 ExprResult RHS =
10467 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10468 if (RHS.isInvalid())
10469 return true;
10470
10471 if (!getDerived().AlwaysRebuild() &&
10472 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10473 return E;
10474
10475 return getDerived().RebuildCXXFoldExpr(
10476 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10477 RHS.get(), E->getLocEnd());
10478 }
10479
10480 // The transform has determined that we should perform an elementwise
10481 // expansion of the pattern. Do so.
10482 ExprResult Result = getDerived().TransformExpr(E->getInit());
10483 if (Result.isInvalid())
10484 return true;
10485 bool LeftFold = E->isLeftFold();
10486
10487 // If we're retaining an expansion for a right fold, it is the innermost
10488 // component and takes the init (if any).
10489 if (!LeftFold && RetainExpansion) {
10490 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10491
10492 ExprResult Out = getDerived().TransformExpr(Pattern);
10493 if (Out.isInvalid())
10494 return true;
10495
10496 Result = getDerived().RebuildCXXFoldExpr(
10497 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10498 Result.get(), E->getLocEnd());
10499 if (Result.isInvalid())
10500 return true;
10501 }
10502
10503 for (unsigned I = 0; I != *NumExpansions; ++I) {
10504 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10505 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10506 ExprResult Out = getDerived().TransformExpr(Pattern);
10507 if (Out.isInvalid())
10508 return true;
10509
10510 if (Out.get()->containsUnexpandedParameterPack()) {
10511 // We still have a pack; retain a pack expansion for this slice.
10512 Result = getDerived().RebuildCXXFoldExpr(
10513 E->getLocStart(),
10514 LeftFold ? Result.get() : Out.get(),
10515 E->getOperator(), E->getEllipsisLoc(),
10516 LeftFold ? Out.get() : Result.get(),
10517 E->getLocEnd());
10518 } else if (Result.isUsable()) {
10519 // We've got down to a single element; build a binary operator.
10520 Result = getDerived().RebuildBinaryOperator(
10521 E->getEllipsisLoc(), E->getOperator(),
10522 LeftFold ? Result.get() : Out.get(),
10523 LeftFold ? Out.get() : Result.get());
10524 } else
10525 Result = Out;
10526
10527 if (Result.isInvalid())
10528 return true;
10529 }
10530
10531 // If we're retaining an expansion for a left fold, it is the outermost
10532 // component and takes the complete expansion so far as its init (if any).
10533 if (LeftFold && RetainExpansion) {
10534 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10535
10536 ExprResult Out = getDerived().TransformExpr(Pattern);
10537 if (Out.isInvalid())
10538 return true;
10539
10540 Result = getDerived().RebuildCXXFoldExpr(
10541 E->getLocStart(), Result.get(),
10542 E->getOperator(), E->getEllipsisLoc(),
10543 Out.get(), E->getLocEnd());
10544 if (Result.isInvalid())
10545 return true;
10546 }
10547
10548 // If we had no init and an empty pack, and we're not retaining an expansion,
10549 // then produce a fallback value or error.
10550 if (Result.isUnset())
10551 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10552 E->getOperator());
10553
10554 return Result;
10555}
10556
10557template<typename Derived>
10558ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010559TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10560 CXXStdInitializerListExpr *E) {
10561 return getDerived().TransformExpr(E->getSubExpr());
10562}
10563
10564template<typename Derived>
10565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010566TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010567 return SemaRef.MaybeBindToTemporary(E);
10568}
10569
10570template<typename Derived>
10571ExprResult
10572TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010573 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010574}
10575
10576template<typename Derived>
10577ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010578TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10579 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10580 if (SubExpr.isInvalid())
10581 return ExprError();
10582
10583 if (!getDerived().AlwaysRebuild() &&
10584 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010585 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010586
10587 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010588}
10589
10590template<typename Derived>
10591ExprResult
10592TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10593 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010594 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010595 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010596 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010597 /*IsCall=*/false, Elements, &ArgChanged))
10598 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010599
Ted Kremeneke65b0862012-03-06 20:05:56 +000010600 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10601 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010602
Ted Kremeneke65b0862012-03-06 20:05:56 +000010603 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10604 Elements.data(),
10605 Elements.size());
10606}
10607
10608template<typename Derived>
10609ExprResult
10610TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010611 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010612 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010613 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010614 bool ArgChanged = false;
10615 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10616 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010617
Ted Kremeneke65b0862012-03-06 20:05:56 +000010618 if (OrigElement.isPackExpansion()) {
10619 // This key/value element is a pack expansion.
10620 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10621 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10622 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10623 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10624
10625 // Determine whether the set of unexpanded parameter packs can
10626 // and should be expanded.
10627 bool Expand = true;
10628 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010629 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10630 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010631 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10632 OrigElement.Value->getLocEnd());
10633 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10634 PatternRange,
10635 Unexpanded,
10636 Expand, RetainExpansion,
10637 NumExpansions))
10638 return ExprError();
10639
10640 if (!Expand) {
10641 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010642 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010643 // expansion.
10644 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10645 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10646 if (Key.isInvalid())
10647 return ExprError();
10648
10649 if (Key.get() != OrigElement.Key)
10650 ArgChanged = true;
10651
10652 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10653 if (Value.isInvalid())
10654 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010655
Ted Kremeneke65b0862012-03-06 20:05:56 +000010656 if (Value.get() != OrigElement.Value)
10657 ArgChanged = true;
10658
Chad Rosier1dcde962012-08-08 18:46:20 +000010659 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010660 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10661 };
10662 Elements.push_back(Expansion);
10663 continue;
10664 }
10665
10666 // Record right away that the argument was changed. This needs
10667 // to happen even if the array expands to nothing.
10668 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010669
Ted Kremeneke65b0862012-03-06 20:05:56 +000010670 // The transform has determined that we should perform an elementwise
10671 // expansion of the pattern. Do so.
10672 for (unsigned I = 0; I != *NumExpansions; ++I) {
10673 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10674 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10675 if (Key.isInvalid())
10676 return ExprError();
10677
10678 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10679 if (Value.isInvalid())
10680 return ExprError();
10681
Chad Rosier1dcde962012-08-08 18:46:20 +000010682 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010683 Key.get(), Value.get(), SourceLocation(), NumExpansions
10684 };
10685
10686 // If any unexpanded parameter packs remain, we still have a
10687 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010688 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010689 if (Key.get()->containsUnexpandedParameterPack() ||
10690 Value.get()->containsUnexpandedParameterPack())
10691 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010692
Ted Kremeneke65b0862012-03-06 20:05:56 +000010693 Elements.push_back(Element);
10694 }
10695
Richard Smith9467be42014-06-06 17:33:35 +000010696 // FIXME: Retain a pack expansion if RetainExpansion is true.
10697
Ted Kremeneke65b0862012-03-06 20:05:56 +000010698 // We've finished with this pack expansion.
10699 continue;
10700 }
10701
10702 // Transform and check key.
10703 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10704 if (Key.isInvalid())
10705 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010706
Ted Kremeneke65b0862012-03-06 20:05:56 +000010707 if (Key.get() != OrigElement.Key)
10708 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010709
Ted Kremeneke65b0862012-03-06 20:05:56 +000010710 // Transform and check value.
10711 ExprResult Value
10712 = getDerived().TransformExpr(OrigElement.Value);
10713 if (Value.isInvalid())
10714 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010715
Ted Kremeneke65b0862012-03-06 20:05:56 +000010716 if (Value.get() != OrigElement.Value)
10717 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010718
10719 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010720 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010721 };
10722 Elements.push_back(Element);
10723 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010724
Ted Kremeneke65b0862012-03-06 20:05:56 +000010725 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10726 return SemaRef.MaybeBindToTemporary(E);
10727
10728 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10729 Elements.data(),
10730 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010731}
10732
Mike Stump11289f42009-09-09 15:08:12 +000010733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010735TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010736 TypeSourceInfo *EncodedTypeInfo
10737 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10738 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010740
Douglas Gregora16548e2009-08-11 05:31:07 +000010741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010742 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010743 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010744
10745 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010746 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010747 E->getRParenLoc());
10748}
Mike Stump11289f42009-09-09 15:08:12 +000010749
Douglas Gregora16548e2009-08-11 05:31:07 +000010750template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010751ExprResult TreeTransform<Derived>::
10752TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010753 // This is a kind of implicit conversion, and it needs to get dropped
10754 // and recomputed for the same general reasons that ImplicitCastExprs
10755 // do, as well a more specific one: this expression is only valid when
10756 // it appears *immediately* as an argument expression.
10757 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010758}
10759
10760template<typename Derived>
10761ExprResult TreeTransform<Derived>::
10762TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010763 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010764 = getDerived().TransformType(E->getTypeInfoAsWritten());
10765 if (!TSInfo)
10766 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010767
John McCall31168b02011-06-15 23:02:42 +000010768 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010769 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010770 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010771
John McCall31168b02011-06-15 23:02:42 +000010772 if (!getDerived().AlwaysRebuild() &&
10773 TSInfo == E->getTypeInfoAsWritten() &&
10774 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010775 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010776
John McCall31168b02011-06-15 23:02:42 +000010777 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010778 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010779 Result.get());
10780}
10781
10782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010784TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010785 // Transform arguments.
10786 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010787 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010788 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010789 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010790 &ArgChanged))
10791 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010792
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010793 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10794 // Class message: transform the receiver type.
10795 TypeSourceInfo *ReceiverTypeInfo
10796 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10797 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010798 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010799
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010800 // If nothing changed, just retain the existing message send.
10801 if (!getDerived().AlwaysRebuild() &&
10802 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010803 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010804
10805 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010806 SmallVector<SourceLocation, 16> SelLocs;
10807 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010808 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10809 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010810 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010811 E->getMethodDecl(),
10812 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010813 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010814 E->getRightLoc());
10815 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010816 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10817 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10818 // Build a new class message send to 'super'.
10819 SmallVector<SourceLocation, 16> SelLocs;
10820 E->getSelectorLocs(SelLocs);
10821 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10822 E->getSelector(),
10823 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010824 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010825 E->getMethodDecl(),
10826 E->getLeftLoc(),
10827 Args,
10828 E->getRightLoc());
10829 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010830
10831 // Instance message: transform the receiver
10832 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10833 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010834 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010835 = getDerived().TransformExpr(E->getInstanceReceiver());
10836 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010837 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010838
10839 // If nothing changed, just retain the existing message send.
10840 if (!getDerived().AlwaysRebuild() &&
10841 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010842 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010843
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010844 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010845 SmallVector<SourceLocation, 16> SelLocs;
10846 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010847 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010848 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010849 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010850 E->getMethodDecl(),
10851 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010852 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010853 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010854}
10855
Mike Stump11289f42009-09-09 15:08:12 +000010856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010858TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010859 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010860}
10861
Mike Stump11289f42009-09-09 15:08:12 +000010862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010864TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010865 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010866}
10867
Mike Stump11289f42009-09-09 15:08:12 +000010868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010870TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010871 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010872 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010873 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010874 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010875
10876 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010877
Douglas Gregord51d90d2010-04-26 20:11:03 +000010878 // If nothing changed, just retain the existing expression.
10879 if (!getDerived().AlwaysRebuild() &&
10880 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010881 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010882
John McCallb268a282010-08-23 23:25:46 +000010883 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010884 E->getLocation(),
10885 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010886}
10887
Mike Stump11289f42009-09-09 15:08:12 +000010888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010890TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010891 // 'super' and types never change. Property never changes. Just
10892 // retain the existing expression.
10893 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010894 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010895
Douglas Gregor9faee212010-04-26 20:47:02 +000010896 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010897 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010898 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010899 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010900
Douglas Gregor9faee212010-04-26 20:47:02 +000010901 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010902
Douglas Gregor9faee212010-04-26 20:47:02 +000010903 // If nothing changed, just retain the existing expression.
10904 if (!getDerived().AlwaysRebuild() &&
10905 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010906 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010907
John McCallb7bd14f2010-12-02 01:19:52 +000010908 if (E->isExplicitProperty())
10909 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10910 E->getExplicitProperty(),
10911 E->getLocation());
10912
10913 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010914 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010915 E->getImplicitPropertyGetter(),
10916 E->getImplicitPropertySetter(),
10917 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010918}
10919
Mike Stump11289f42009-09-09 15:08:12 +000010920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010921ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010922TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10923 // Transform the base expression.
10924 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10925 if (Base.isInvalid())
10926 return ExprError();
10927
10928 // Transform the key expression.
10929 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10930 if (Key.isInvalid())
10931 return ExprError();
10932
10933 // If nothing changed, just retain the existing expression.
10934 if (!getDerived().AlwaysRebuild() &&
10935 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010936 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010937
Chad Rosier1dcde962012-08-08 18:46:20 +000010938 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010939 Base.get(), Key.get(),
10940 E->getAtIndexMethodDecl(),
10941 E->setAtIndexMethodDecl());
10942}
10943
10944template<typename Derived>
10945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010946TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010947 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010948 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010949 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010951
Douglas Gregord51d90d2010-04-26 20:11:03 +000010952 // If nothing changed, just retain the existing expression.
10953 if (!getDerived().AlwaysRebuild() &&
10954 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010955 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010956
John McCallb268a282010-08-23 23:25:46 +000010957 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010958 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010959 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010960}
10961
Mike Stump11289f42009-09-09 15:08:12 +000010962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010964TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010965 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010966 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010967 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010968 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010969 SubExprs, &ArgumentChanged))
10970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010971
Douglas Gregora16548e2009-08-11 05:31:07 +000010972 if (!getDerived().AlwaysRebuild() &&
10973 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010974 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010975
Douglas Gregora16548e2009-08-11 05:31:07 +000010976 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010977 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010978 E->getRParenLoc());
10979}
10980
Mike Stump11289f42009-09-09 15:08:12 +000010981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010982ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010983TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10984 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10985 if (SrcExpr.isInvalid())
10986 return ExprError();
10987
10988 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10989 if (!Type)
10990 return ExprError();
10991
10992 if (!getDerived().AlwaysRebuild() &&
10993 Type == E->getTypeSourceInfo() &&
10994 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010995 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010996
10997 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10998 SrcExpr.get(), Type,
10999 E->getRParenLoc());
11000}
11001
11002template<typename Derived>
11003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011004TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011005 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011006
Craig Topperc3ec1492014-05-26 06:22:03 +000011007 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011008 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11009
11010 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011011 blockScope->TheDecl->setBlockMissingReturnType(
11012 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011013
Chris Lattner01cf8db2011-07-20 06:58:45 +000011014 SmallVector<ParmVarDecl*, 4> params;
11015 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011016
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011017 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000011018 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11019 oldBlock->param_begin(),
11020 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011021 nullptr, paramTypes, &params)) {
11022 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011023 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011024 }
John McCall490112f2011-02-04 18:33:18 +000011025
Jordan Rosea0a86be2013-03-08 22:25:36 +000011026 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000011027 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011028 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011029
Jordan Rose5c382722013-03-08 21:51:21 +000011030 QualType functionType =
11031 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011032 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000011033 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011034
11035 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011036 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011037 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011038
11039 if (!oldBlock->blockMissingReturnType()) {
11040 blockScope->HasImplicitReturnType = false;
11041 blockScope->ReturnType = exprResultType;
11042 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011043
John McCall3882ace2011-01-05 12:14:39 +000011044 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011045 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011046 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011047 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011048 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011049 }
John McCall3882ace2011-01-05 12:14:39 +000011050
John McCall490112f2011-02-04 18:33:18 +000011051#ifndef NDEBUG
11052 // In builds with assertions, make sure that we captured everything we
11053 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011054 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011055 for (const auto &I : oldBlock->captures()) {
11056 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011057
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011058 // Ignore parameter packs.
11059 if (isa<ParmVarDecl>(oldCapture) &&
11060 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11061 continue;
John McCall490112f2011-02-04 18:33:18 +000011062
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011063 VarDecl *newCapture =
11064 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11065 oldCapture));
11066 assert(blockScope->CaptureMap.count(newCapture));
11067 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011068 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011069 }
11070#endif
11071
11072 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011073 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011074}
11075
Mike Stump11289f42009-09-09 15:08:12 +000011076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011077ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011078TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011079 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011080}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011081
11082template<typename Derived>
11083ExprResult
11084TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011085 QualType RetTy = getDerived().TransformType(E->getType());
11086 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011087 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011088 SubExprs.reserve(E->getNumSubExprs());
11089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11090 SubExprs, &ArgumentChanged))
11091 return ExprError();
11092
11093 if (!getDerived().AlwaysRebuild() &&
11094 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011095 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011096
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011097 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011098 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011099}
Chad Rosier1dcde962012-08-08 18:46:20 +000011100
Douglas Gregora16548e2009-08-11 05:31:07 +000011101//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011102// Type reconstruction
11103//===----------------------------------------------------------------------===//
11104
Mike Stump11289f42009-09-09 15:08:12 +000011105template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011106QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11107 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011108 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011109 getDerived().getBaseEntity());
11110}
11111
Mike Stump11289f42009-09-09 15:08:12 +000011112template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011113QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11114 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011115 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011116 getDerived().getBaseEntity());
11117}
11118
Mike Stump11289f42009-09-09 15:08:12 +000011119template<typename Derived>
11120QualType
John McCall70dd5f62009-10-30 00:06:24 +000011121TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11122 bool WrittenAsLValue,
11123 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011124 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011125 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011126}
11127
11128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011129QualType
John McCall70dd5f62009-10-30 00:06:24 +000011130TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11131 QualType ClassType,
11132 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011133 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11134 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011135}
11136
11137template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011138QualType TreeTransform<Derived>::RebuildObjCObjectType(
11139 QualType BaseType,
11140 SourceLocation Loc,
11141 SourceLocation TypeArgsLAngleLoc,
11142 ArrayRef<TypeSourceInfo *> TypeArgs,
11143 SourceLocation TypeArgsRAngleLoc,
11144 SourceLocation ProtocolLAngleLoc,
11145 ArrayRef<ObjCProtocolDecl *> Protocols,
11146 ArrayRef<SourceLocation> ProtocolLocs,
11147 SourceLocation ProtocolRAngleLoc) {
11148 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11149 TypeArgs, TypeArgsRAngleLoc,
11150 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11151 ProtocolRAngleLoc,
11152 /*FailOnError=*/true);
11153}
11154
11155template<typename Derived>
11156QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11157 QualType PointeeType,
11158 SourceLocation Star) {
11159 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11160}
11161
11162template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011163QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011164TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11165 ArrayType::ArraySizeModifier SizeMod,
11166 const llvm::APInt *Size,
11167 Expr *SizeExpr,
11168 unsigned IndexTypeQuals,
11169 SourceRange BracketsRange) {
11170 if (SizeExpr || !Size)
11171 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11172 IndexTypeQuals, BracketsRange,
11173 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011174
11175 QualType Types[] = {
11176 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11177 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11178 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011179 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011180 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011181 QualType SizeType;
11182 for (unsigned I = 0; I != NumTypes; ++I)
11183 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11184 SizeType = Types[I];
11185 break;
11186 }
Mike Stump11289f42009-09-09 15:08:12 +000011187
Eli Friedman9562f392012-01-25 23:20:27 +000011188 // Note that we can return a VariableArrayType here in the case where
11189 // the element type was a dependent VariableArrayType.
11190 IntegerLiteral *ArraySize
11191 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11192 /*FIXME*/BracketsRange.getBegin());
11193 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011194 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011195 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011196}
Mike Stump11289f42009-09-09 15:08:12 +000011197
Douglas Gregord6ff3322009-08-04 16:50:30 +000011198template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011199QualType
11200TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011201 ArrayType::ArraySizeModifier SizeMod,
11202 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011203 unsigned IndexTypeQuals,
11204 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011205 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011206 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011207}
11208
11209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011210QualType
Mike Stump11289f42009-09-09 15:08:12 +000011211TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011212 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011213 unsigned IndexTypeQuals,
11214 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011215 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011216 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011217}
Mike Stump11289f42009-09-09 15:08:12 +000011218
Douglas Gregord6ff3322009-08-04 16:50:30 +000011219template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011220QualType
11221TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011222 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011223 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011224 unsigned IndexTypeQuals,
11225 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011226 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011227 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011228 IndexTypeQuals, BracketsRange);
11229}
11230
11231template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011232QualType
11233TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011234 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011235 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011236 unsigned IndexTypeQuals,
11237 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011238 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011239 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011240 IndexTypeQuals, BracketsRange);
11241}
11242
11243template<typename Derived>
11244QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011245 unsigned NumElements,
11246 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011247 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011248 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011249}
Mike Stump11289f42009-09-09 15:08:12 +000011250
Douglas Gregord6ff3322009-08-04 16:50:30 +000011251template<typename Derived>
11252QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11253 unsigned NumElements,
11254 SourceLocation AttributeLoc) {
11255 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11256 NumElements, true);
11257 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011258 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11259 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011260 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011261}
Mike Stump11289f42009-09-09 15:08:12 +000011262
Douglas Gregord6ff3322009-08-04 16:50:30 +000011263template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011264QualType
11265TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011266 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011267 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011268 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011269}
Mike Stump11289f42009-09-09 15:08:12 +000011270
Douglas Gregord6ff3322009-08-04 16:50:30 +000011271template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011272QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11273 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011274 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011275 const FunctionProtoType::ExtProtoInfo &EPI) {
11276 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011277 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011278 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011279 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011280}
Mike Stump11289f42009-09-09 15:08:12 +000011281
Douglas Gregord6ff3322009-08-04 16:50:30 +000011282template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011283QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11284 return SemaRef.Context.getFunctionNoProtoType(T);
11285}
11286
11287template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011288QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11289 assert(D && "no decl found");
11290 if (D->isInvalidDecl()) return QualType();
11291
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011292 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011293 TypeDecl *Ty;
11294 if (isa<UsingDecl>(D)) {
11295 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011296 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011297 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11298
11299 // A valid resolved using typename decl points to exactly one type decl.
11300 assert(++Using->shadow_begin() == Using->shadow_end());
11301 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011302
John McCallb96ec562009-12-04 22:46:56 +000011303 } else {
11304 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11305 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11306 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11307 }
11308
11309 return SemaRef.Context.getTypeDeclType(Ty);
11310}
11311
11312template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011313QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11314 SourceLocation Loc) {
11315 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011316}
11317
11318template<typename Derived>
11319QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11320 return SemaRef.Context.getTypeOfType(Underlying);
11321}
11322
11323template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011324QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11325 SourceLocation Loc) {
11326 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011327}
11328
11329template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011330QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11331 UnaryTransformType::UTTKind UKind,
11332 SourceLocation Loc) {
11333 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11334}
11335
11336template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011337QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011338 TemplateName Template,
11339 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011340 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011341 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011342}
Mike Stump11289f42009-09-09 15:08:12 +000011343
Douglas Gregor1135c352009-08-06 05:28:30 +000011344template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011345QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11346 SourceLocation KWLoc) {
11347 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11348}
11349
11350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011351TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011352TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011353 bool TemplateKW,
11354 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011355 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011356 Template);
11357}
11358
11359template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011360TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011361TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11362 const IdentifierInfo &Name,
11363 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011364 QualType ObjectType,
11365 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011366 UnqualifiedId TemplateName;
11367 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011368 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011369 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011370 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011371 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011372 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011373 /*EnteringContext=*/false,
11374 Template);
John McCall31f82722010-11-12 08:19:04 +000011375 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011376}
Mike Stump11289f42009-09-09 15:08:12 +000011377
Douglas Gregora16548e2009-08-11 05:31:07 +000011378template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011379TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011380TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011381 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011382 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011383 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011384 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011385 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011386 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011387 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011388 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011389 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011390 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011391 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011392 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011393 /*EnteringContext=*/false,
11394 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011395 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011396}
Chad Rosier1dcde962012-08-08 18:46:20 +000011397
Douglas Gregor71395fa2009-11-04 00:56:37 +000011398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011399ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011400TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11401 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011402 Expr *OrigCallee,
11403 Expr *First,
11404 Expr *Second) {
11405 Expr *Callee = OrigCallee->IgnoreParenCasts();
11406 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011407
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011408 if (First->getObjectKind() == OK_ObjCProperty) {
11409 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11410 if (BinaryOperator::isAssignmentOp(Opc))
11411 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11412 First, Second);
11413 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11414 if (Result.isInvalid())
11415 return ExprError();
11416 First = Result.get();
11417 }
11418
11419 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11420 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11421 if (Result.isInvalid())
11422 return ExprError();
11423 Second = Result.get();
11424 }
11425
Douglas Gregora16548e2009-08-11 05:31:07 +000011426 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011427 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011428 if (!First->getType()->isOverloadableType() &&
11429 !Second->getType()->isOverloadableType())
11430 return getSema().CreateBuiltinArraySubscriptExpr(First,
11431 Callee->getLocStart(),
11432 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011433 } else if (Op == OO_Arrow) {
11434 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011435 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11436 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011437 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011438 // The argument is not of overloadable type, so try to create a
11439 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011440 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011441 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011442
John McCallb268a282010-08-23 23:25:46 +000011443 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011444 }
11445 } else {
John McCallb268a282010-08-23 23:25:46 +000011446 if (!First->getType()->isOverloadableType() &&
11447 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011448 // Neither of the arguments is an overloadable type, so try to
11449 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011450 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011451 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011452 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011453 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011454 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011455
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011456 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011457 }
11458 }
Mike Stump11289f42009-09-09 15:08:12 +000011459
11460 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011461 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011462 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011463
John McCallb268a282010-08-23 23:25:46 +000011464 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011465 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011466 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011467 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011468 // If we've resolved this to a particular non-member function, just call
11469 // that function. If we resolved it to a member function,
11470 // CreateOverloaded* will find that function for us.
11471 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11472 if (!isa<CXXMethodDecl>(ND))
11473 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011474 }
Mike Stump11289f42009-09-09 15:08:12 +000011475
Douglas Gregora16548e2009-08-11 05:31:07 +000011476 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011477 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011478 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011479
Douglas Gregora16548e2009-08-11 05:31:07 +000011480 // Create the overloaded operator invocation for unary operators.
11481 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011482 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011483 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011484 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011485 }
Mike Stump11289f42009-09-09 15:08:12 +000011486
Douglas Gregore9d62932011-07-15 16:25:15 +000011487 if (Op == OO_Subscript) {
11488 SourceLocation LBrace;
11489 SourceLocation RBrace;
11490
11491 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011492 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011493 LBrace = SourceLocation::getFromRawEncoding(
11494 NameLoc.CXXOperatorName.BeginOpNameLoc);
11495 RBrace = SourceLocation::getFromRawEncoding(
11496 NameLoc.CXXOperatorName.EndOpNameLoc);
11497 } else {
11498 LBrace = Callee->getLocStart();
11499 RBrace = OpLoc;
11500 }
11501
11502 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11503 First, Second);
11504 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011505
Douglas Gregora16548e2009-08-11 05:31:07 +000011506 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011507 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011508 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011509 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11510 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011512
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011513 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011514}
Mike Stump11289f42009-09-09 15:08:12 +000011515
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011516template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011517ExprResult
John McCallb268a282010-08-23 23:25:46 +000011518TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011519 SourceLocation OperatorLoc,
11520 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011521 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011522 TypeSourceInfo *ScopeType,
11523 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011524 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011525 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011526 QualType BaseType = Base->getType();
11527 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011528 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011529 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011530 !BaseType->getAs<PointerType>()->getPointeeType()
11531 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011532 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011533 return SemaRef.BuildPseudoDestructorExpr(
11534 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11535 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011536 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011537
Douglas Gregor678f90d2010-02-25 01:56:36 +000011538 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011539 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11540 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11541 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11542 NameInfo.setNamedTypeInfo(DestroyedType);
11543
Richard Smith8e4a3862012-05-15 06:15:11 +000011544 // The scope type is now known to be a valid nested name specifier
11545 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011546 if (ScopeType) {
11547 if (!ScopeType->getType()->getAs<TagType>()) {
11548 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11549 diag::err_expected_class_or_namespace)
11550 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11551 return ExprError();
11552 }
11553 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11554 CCLoc);
11555 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011556
Abramo Bagnara7945c982012-01-27 09:46:47 +000011557 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011558 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011559 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011560 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011561 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011562 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011563 /*TemplateArgs*/ nullptr,
11564 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011565}
11566
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011567template<typename Derived>
11568StmtResult
11569TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011570 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011571 CapturedDecl *CD = S->getCapturedDecl();
11572 unsigned NumParams = CD->getNumParams();
11573 unsigned ContextParamPos = CD->getContextParamPosition();
11574 SmallVector<Sema::CapturedParamNameType, 4> Params;
11575 for (unsigned I = 0; I < NumParams; ++I) {
11576 if (I != ContextParamPos) {
11577 Params.push_back(
11578 std::make_pair(
11579 CD->getParam(I)->getName(),
11580 getDerived().TransformType(CD->getParam(I)->getType())));
11581 } else {
11582 Params.push_back(std::make_pair(StringRef(), QualType()));
11583 }
11584 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011585 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011586 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011587 StmtResult Body;
11588 {
11589 Sema::CompoundScopeRAII CompoundScope(getSema());
11590 Body = getDerived().TransformStmt(S->getCapturedStmt());
11591 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011592
11593 if (Body.isInvalid()) {
11594 getSema().ActOnCapturedRegionError();
11595 return StmtError();
11596 }
11597
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011598 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011599}
11600
Douglas Gregord6ff3322009-08-04 16:50:30 +000011601} // end namespace clang
11602
Hans Wennborg59dbe862015-09-29 20:56:43 +000011603#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H