blob: c1cf9ada71e22a23dfef0db4235596f765924c9e [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.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *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
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000702 /// \brief Build an Objective-C object type.
703 ///
704 /// By default, performs semantic analysis when building the object type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildObjCObjectType(QualType BaseType,
707 SourceLocation Loc,
708 SourceLocation TypeArgsLAngleLoc,
709 ArrayRef<TypeSourceInfo *> TypeArgs,
710 SourceLocation TypeArgsRAngleLoc,
711 SourceLocation ProtocolLAngleLoc,
712 ArrayRef<ObjCProtocolDecl *> Protocols,
713 ArrayRef<SourceLocation> ProtocolLocs,
714 SourceLocation ProtocolRAngleLoc);
715
716 /// \brief Build a new Objective-C object pointer type given the pointee type.
717 ///
718 /// By default, directly builds the pointer type, with no additional semantic
719 /// analysis.
720 QualType RebuildObjCObjectPointerType(QualType PointeeType,
721 SourceLocation Star);
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new array type given the element type, size
724 /// modifier, size of the array (if known), size expression, and index type
725 /// qualifiers.
726 ///
727 /// By default, performs semantic analysis when building the array type.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 QualType RebuildArrayType(QualType ElementType,
731 ArrayType::ArraySizeModifier SizeMod,
732 const llvm::APInt *Size,
733 Expr *SizeExpr,
734 unsigned IndexTypeQuals,
735 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737 /// \brief Build a new constant array type given the element type, size
738 /// modifier, (known) size of the array, and index type qualifiers.
739 ///
740 /// By default, performs semantic analysis when building the array type.
741 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000742 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 ArrayType::ArraySizeModifier SizeMod,
744 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000745 unsigned IndexTypeQuals,
746 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new incomplete array type given the element type, size
749 /// modifier, and index type qualifiers.
750 ///
751 /// By default, performs semantic analysis when building the array type.
752 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000753 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757
Mike Stump11289f42009-09-09 15:08:12 +0000758 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 /// size modifier, size expression, and index type qualifiers.
760 ///
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000763 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000765 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 unsigned IndexTypeQuals,
767 SourceRange BracketsRange);
768
Mike Stump11289f42009-09-09 15:08:12 +0000769 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// size modifier, size expression, and index type qualifiers.
771 ///
772 /// By default, performs semantic analysis when building the array type.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000774 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000776 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 unsigned IndexTypeQuals,
778 SourceRange BracketsRange);
779
780 /// \brief Build a new vector type given the element type and
781 /// number of elements.
782 ///
783 /// By default, performs semantic analysis when building the vector type.
784 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000785 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000786 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000787
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// \brief Build a new extended vector type given the element type and
789 /// number of elements.
790 ///
791 /// By default, performs semantic analysis when building the vector type.
792 /// Subclasses may override this routine to provide different behavior.
793 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
796 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 /// given the element type and number of elements.
798 ///
799 /// By default, performs semantic analysis when building the vector type.
800 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000801 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000802 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new function type.
806 ///
807 /// By default, performs semantic analysis when building the function type.
808 /// Subclasses may override this routine to provide different behavior.
809 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000810 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000811 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000812
John McCall550e0c22009-10-21 00:40:46 +0000813 /// \brief Build a new unprototyped function type.
814 QualType RebuildFunctionNoProtoType(QualType ResultType);
815
John McCallb96ec562009-12-04 22:46:56 +0000816 /// \brief Rebuild an unresolved typename type, given the decl that
817 /// the UnresolvedUsingTypenameDecl was transformed to.
818 QualType RebuildUnresolvedUsingType(Decl *D);
819
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000821 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 return SemaRef.Context.getTypeDeclType(Typedef);
823 }
824
825 /// \brief Build a new class/struct/union type.
826 QualType RebuildRecordType(RecordDecl *Record) {
827 return SemaRef.Context.getTypeDeclType(Record);
828 }
829
830 /// \brief Build a new Enum type.
831 QualType RebuildEnumType(EnumDecl *Enum) {
832 return SemaRef.Context.getTypeDeclType(Enum);
833 }
John McCallfcc33b02009-09-05 00:15:47 +0000834
Mike Stump11289f42009-09-09 15:08:12 +0000835 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 ///
837 /// By default, performs semantic analysis when building the typeof type.
838 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000839 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, builds a new TypeOfType with the given underlying type.
844 QualType RebuildTypeOfType(QualType Underlying);
845
Alexis Hunte852b102011-05-24 22:41:36 +0000846 /// \brief Build a new unary transform type.
847 QualType RebuildUnaryTransformType(QualType BaseType,
848 UnaryTransformType::UTTKind UKind,
849 SourceLocation Loc);
850
Richard Smith74aeef52013-04-26 16:15:35 +0000851 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 ///
853 /// By default, performs semantic analysis when building the decltype type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000855 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000858 ///
859 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000860 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000861 // Note, IsDependent is always false here: we implicitly convert an 'auto'
862 // which has been deduced to a dependent type into an undeduced 'auto', so
863 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000864 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000865 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000866 }
867
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868 /// \brief Build a new template specialization type.
869 ///
870 /// By default, performs semantic analysis when building the template
871 /// specialization type. Subclasses may override this routine to provide
872 /// different behavior.
873 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000874 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000875 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000876
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000877 /// \brief Build a new parenthesized type.
878 ///
879 /// By default, builds a new ParenType type from the inner type.
880 /// Subclasses may override this routine to provide different behavior.
881 QualType RebuildParenType(QualType InnerType) {
882 return SemaRef.Context.getParenType(InnerType);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new qualified name type.
886 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000887 /// By default, builds a new ElaboratedType type from the keyword,
888 /// the nested-name-specifier and the named type.
889 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000890 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
891 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getElaboratedType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000896 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000897 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000898
899 /// \brief Build a new typename type that refers to a template-id.
900 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000901 /// By default, builds a new DependentNameType type from the
902 /// nested-name-specifier and the given type. Subclasses may override
903 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000904 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 ElaboratedTypeKeyword Keyword,
906 NestedNameSpecifierLoc QualifierLoc,
907 const IdentifierInfo *Name,
908 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000909 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000910 // Rebuild the template name.
911 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000912 CXXScopeSpec SS;
913 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000915 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
916 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000917
Douglas Gregora7a795b2011-03-01 20:11:18 +0000918 if (InstName.isNull())
919 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000920
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 // If it's still dependent, make a dependent specialization.
922 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
Douglas Gregora7a795b2011-03-01 20:11:18 +0000928 // Otherwise, make an elaborated type wrapping a non-dependent
929 // specialization.
930 QualType T =
931 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
932 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Craig Topperc3ec1492014-05-26 06:22:03 +0000934 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000935 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000939 T);
940 }
941
Douglas Gregord6ff3322009-08-04 16:50:30 +0000942 /// \brief Build a new typename type that refers to an identifier.
943 ///
944 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000946 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000947 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000948 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000949 NestedNameSpecifierLoc QualifierLoc,
950 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000953 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 // If the name is still dependent, just build a new dependent name type.
957 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000958 return SemaRef.Context.getDependentNameType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000960 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 }
962
Abramo Bagnara6150c882010-05-11 21:36:43 +0000963 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000964 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000965 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000966
967 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
968
Abramo Bagnarad7548482010-05-19 21:37:53 +0000969 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000970 // into a non-dependent elaborated-type-specifier. Find the tag we're
971 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000972 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000973 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
974 if (!DC)
975 return QualType();
976
John McCallbf8c5192010-05-27 06:40:31 +0000977 if (SemaRef.RequireCompleteDeclContext(SS, DC))
978 return QualType();
979
Craig Topperc3ec1492014-05-26 06:22:03 +0000980 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000981 SemaRef.LookupQualifiedName(Result, DC);
982 switch (Result.getResultKind()) {
983 case LookupResult::NotFound:
984 case LookupResult::NotFoundInCurrentInstantiation:
985 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000986
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 case LookupResult::Found:
988 Tag = Result.getAsSingle<TagDecl>();
989 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000990
Douglas Gregore677daf2010-03-31 22:19:08 +0000991 case LookupResult::FoundOverloaded:
992 case LookupResult::FoundUnresolvedValue:
993 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000994
Douglas Gregore677daf2010-03-31 22:19:08 +0000995 case LookupResult::Ambiguous:
996 // Let the LookupResult structure handle ambiguities.
997 return QualType();
998 }
999
1000 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 // Check where the name exists but isn't a tag type and use that to emit
1002 // better diagnostics.
1003 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1004 SemaRef.LookupQualifiedName(Result, DC);
1005 switch (Result.getResultKind()) {
1006 case LookupResult::Found:
1007 case LookupResult::FoundOverloaded:
1008 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001009 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 unsigned Kind = 0;
1011 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001012 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1013 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001014 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1015 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1016 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001017 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001018 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001019 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001020 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001021 break;
1022 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001023 return QualType();
1024 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001025
Richard Trieucaa33d32011-06-10 03:11:26 +00001026 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001027 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001028 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1030 return QualType();
1031 }
1032
1033 // Build the elaborated-type-specifier type.
1034 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 return SemaRef.Context.getElaboratedType(Keyword,
1036 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001037 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregor822d0302011-01-12 17:07:58 +00001040 /// \brief Build a new pack expansion type.
1041 ///
1042 /// By default, builds a new PackExpansionType type from the given pattern.
1043 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001044 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001045 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001046 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001047 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001048 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1049 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001050 }
1051
Eli Friedman0dfb8892011-10-06 23:00:33 +00001052 /// \brief Build a new atomic type given its value type.
1053 ///
1054 /// By default, performs semantic analysis when building the atomic type.
1055 /// Subclasses may override this routine to provide different behavior.
1056 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1057
Xiuli Pan9c14e282016-01-09 12:53:17 +00001058 /// \brief Build a new pipe type given its value type.
1059 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1060
Douglas Gregor71dc5092009-08-06 06:41:21 +00001061 /// \brief Build a new template name given a nested name specifier, a flag
1062 /// indicating whether the "template" keyword was provided, and the template
1063 /// that the template name refers to.
1064 ///
1065 /// By default, builds the new template name directly. Subclasses may override
1066 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001067 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001068 bool TemplateKW,
1069 TemplateDecl *Template);
1070
Douglas Gregor71dc5092009-08-06 06:41:21 +00001071 /// \brief Build a new template name given a nested name specifier and the
1072 /// name that is referred to as a template.
1073 ///
1074 /// By default, performs semantic analysis to determine whether the name can
1075 /// be resolved to a specific template, then builds the appropriate kind of
1076 /// template name. Subclasses may override this routine to provide different
1077 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001078 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1079 const IdentifierInfo &Name,
1080 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001081 QualType ObjectType,
1082 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregor71395fa2009-11-04 00:56:37 +00001084 /// \brief Build a new template name given a nested name specifier and the
1085 /// overloaded operator name that is referred to as a template.
1086 ///
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.
Douglas Gregor9db53502011-03-02 18:07:45 +00001091 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001092 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001093 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001094 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001095
1096 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001097 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001098 ///
1099 /// By default, performs semantic analysis to determine whether the name can
1100 /// be resolved to a specific template, then builds the appropriate kind of
1101 /// template name. Subclasses may override this routine to provide different
1102 /// behavior.
1103 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1104 const TemplateArgument &ArgPack) {
1105 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1106 }
1107
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 /// \brief Build a new compound 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 RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 MultiStmtArg Statements,
1114 SourceLocation RBraceLoc,
1115 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001116 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 IsStmtExpr);
1118 }
1119
1120 /// \brief Build a new case statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001124 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001125 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001127 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001129 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 ColonLoc);
1131 }
Mike Stump11289f42009-09-09 15:08:12 +00001132
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 /// \brief Attach the body to a new case statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001137 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 getSema().ActOnCaseStmtBody(S, Body);
1139 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Build a new default statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Stmt *SubStmt) {
1149 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001150 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 }
Mike Stump11289f42009-09-09 15:08:12 +00001152
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 /// \brief Build a new label statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001157 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1158 SourceLocation ColonLoc, Stmt *SubStmt) {
1159 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Richard Smithc202b282012-04-14 00:33:13 +00001162 /// \brief Build a new label statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001166 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1167 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001168 Stmt *SubStmt) {
1169 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1170 }
1171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new "if" statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001176 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1177 Sema::ConditionResult Cond, Stmt *Then,
1178 SourceLocation ElseLoc, Stmt *Else) {
1179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Cond, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Douglas Gregorebe10102009-08-20 07:17:43 +00001182 /// \brief Start building a new switch statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001187 Sema::ConditionResult Cond) {
1188 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Attach the body to the switch statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001195 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001196 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001197 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
1199
1200 /// \brief Build a new while statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001204 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1205 Sema::ConditionResult Cond, Stmt *Body) {
1206 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregorebe10102009-08-20 07:17:43 +00001209 /// \brief Build a new do-while statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001213 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001214 SourceLocation WhileLoc, SourceLocation LParenLoc,
1215 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001216 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1217 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 }
1219
1220 /// \brief Build a new for statement.
1221 ///
1222 /// By default, performs semantic analysis to build the new statement.
1223 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001224 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001225 Stmt *Init, Sema::ConditionResult Cond,
1226 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1227 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001228 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001229 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 /// \brief Build a new goto statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001236 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1237 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001238 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001239 }
1240
1241 /// \brief Build a new indirect goto statement.
1242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001246 SourceLocation StarLoc,
1247 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001248 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 /// \brief Build a new return statement.
1252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001255 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001256 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 /// \brief Build a new declaration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001263 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001264 SourceLocation StartLoc, SourceLocation EndLoc) {
1265 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001266 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Anders Carlssonaaeef072010-01-24 05:50:09 +00001269 /// \brief Build a new inline asm statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001273 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1274 bool IsVolatile, unsigned NumOutputs,
1275 unsigned NumInputs, IdentifierInfo **Names,
1276 MultiExprArg Constraints, MultiExprArg Exprs,
1277 Expr *AsmString, MultiExprArg Clobbers,
1278 SourceLocation RParenLoc) {
1279 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1280 NumInputs, Names, Constraints, Exprs,
1281 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001282 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001283
Chad Rosier32503022012-06-11 20:47:18 +00001284 /// \brief Build a new MS style inline asm statement.
1285 ///
1286 /// By default, performs semantic analysis to build the new statement.
1287 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001288 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001289 ArrayRef<Token> AsmToks,
1290 StringRef AsmString,
1291 unsigned NumOutputs, unsigned NumInputs,
1292 ArrayRef<StringRef> Constraints,
1293 ArrayRef<StringRef> Clobbers,
1294 ArrayRef<Expr*> Exprs,
1295 SourceLocation EndLoc) {
1296 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1297 NumOutputs, NumInputs,
1298 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001299 }
1300
Richard Smith9f690bd2015-10-27 06:02:45 +00001301 /// \brief Build a new co_return statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1306 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1307 }
1308
1309 /// \brief Build a new co_await expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1314 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1315 }
1316
1317 /// \brief Build a new co_yield expression.
1318 ///
1319 /// By default, performs semantic analysis to build the new expression.
1320 /// Subclasses may override this routine to provide different behavior.
1321 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1322 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1323 }
1324
James Dennett2a4d13c2012-06-15 07:13:21 +00001325 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001330 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001331 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001332 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001333 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001334 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001335 }
1336
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001337 /// \brief Rebuild an Objective-C exception declaration.
1338 ///
1339 /// By default, performs semantic analysis to build the new declaration.
1340 /// Subclasses may override this routine to provide different behavior.
1341 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1342 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001343 return getSema().BuildObjCExceptionDecl(TInfo, T,
1344 ExceptionDecl->getInnerLocStart(),
1345 ExceptionDecl->getLocation(),
1346 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001348
James Dennett2a4d13c2012-06-15 07:13:21 +00001349 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001350 ///
1351 /// By default, performs semantic analysis to build the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001354 SourceLocation RParenLoc,
1355 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001356 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001357 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001360
James Dennett2a4d13c2012-06-15 07:13:21 +00001361 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001365 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001366 Stmt *Body) {
1367 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001369
James Dennett2a4d13c2012-06-15 07:13:21 +00001370 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001371 ///
1372 /// By default, performs semantic analysis to build the new statement.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Operand) {
1376 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001378
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001379 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001383 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001384 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001385 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001386 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001387 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001388 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001389 return getSema().ActOnOpenMPExecutableDirective(
1390 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001391 }
1392
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001393 /// \brief Build a new OpenMP 'if' clause.
1394 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001395 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001396 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001397 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1398 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001399 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001400 SourceLocation NameModifierLoc,
1401 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001402 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001403 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1404 LParenLoc, NameModifierLoc, ColonLoc,
1405 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001406 }
1407
Alexey Bataev3778b602014-07-17 07:32:53 +00001408 /// \brief Build a new OpenMP 'final' clause.
1409 ///
1410 /// By default, performs semantic analysis to build the new OpenMP clause.
1411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1413 SourceLocation LParenLoc,
1414 SourceLocation EndLoc) {
1415 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1416 EndLoc);
1417 }
1418
Alexey Bataev568a8332014-03-06 06:15:19 +00001419 /// \brief Build a new OpenMP 'num_threads' clause.
1420 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001421 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001422 /// Subclasses may override this routine to provide different behavior.
1423 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1428 LParenLoc, EndLoc);
1429 }
1430
Alexey Bataev62c87d22014-03-21 04:51:18 +00001431 /// \brief Build a new OpenMP 'safelen' clause.
1432 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001433 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001434 /// Subclasses may override this routine to provide different behavior.
1435 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1439 }
1440
Alexey Bataev66b15b52015-08-21 11:14:16 +00001441 /// \brief Build a new OpenMP 'simdlen' clause.
1442 ///
1443 /// By default, performs semantic analysis to build the new OpenMP clause.
1444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1449 }
1450
Alexander Musman8bd31e62014-05-27 15:12:19 +00001451 /// \brief Build a new OpenMP 'collapse' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1459 EndLoc);
1460 }
1461
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001462 /// \brief Build a new OpenMP 'default' clause.
1463 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001464 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001465 /// Subclasses may override this routine to provide different behavior.
1466 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1467 SourceLocation KindKwLoc,
1468 SourceLocation StartLoc,
1469 SourceLocation LParenLoc,
1470 SourceLocation EndLoc) {
1471 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1472 StartLoc, LParenLoc, EndLoc);
1473 }
1474
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001475 /// \brief Build a new OpenMP 'proc_bind' clause.
1476 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001477 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001478 /// Subclasses may override this routine to provide different behavior.
1479 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1480 SourceLocation KindKwLoc,
1481 SourceLocation StartLoc,
1482 SourceLocation LParenLoc,
1483 SourceLocation EndLoc) {
1484 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1485 StartLoc, LParenLoc, EndLoc);
1486 }
1487
Alexey Bataev56dafe82014-06-20 07:16:17 +00001488 /// \brief Build a new OpenMP 'schedule' clause.
1489 ///
1490 /// By default, performs semantic analysis to build the new OpenMP clause.
1491 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001492 OMPClause *RebuildOMPScheduleClause(
1493 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1494 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1495 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1496 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001497 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001498 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1499 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001500 }
1501
Alexey Bataev10e775f2015-07-30 11:36:16 +00001502 /// \brief Build a new OpenMP 'ordered' clause.
1503 ///
1504 /// By default, performs semantic analysis to build the new OpenMP clause.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1507 SourceLocation EndLoc,
1508 SourceLocation LParenLoc, Expr *Num) {
1509 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1510 }
1511
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001512 /// \brief Build a new OpenMP 'private' clause.
1513 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001514 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001515 /// Subclasses may override this routine to provide different behavior.
1516 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1517 SourceLocation StartLoc,
1518 SourceLocation LParenLoc,
1519 SourceLocation EndLoc) {
1520 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1521 EndLoc);
1522 }
1523
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001524 /// \brief Build a new OpenMP 'firstprivate' clause.
1525 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001526 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001527 /// Subclasses may override this routine to provide different behavior.
1528 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1529 SourceLocation StartLoc,
1530 SourceLocation LParenLoc,
1531 SourceLocation EndLoc) {
1532 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1533 EndLoc);
1534 }
1535
Alexander Musman1bb328c2014-06-04 13:06:39 +00001536 /// \brief Build a new OpenMP 'lastprivate' clause.
1537 ///
1538 /// By default, performs semantic analysis to build the new OpenMP clause.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1541 SourceLocation StartLoc,
1542 SourceLocation LParenLoc,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1545 EndLoc);
1546 }
1547
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001548 /// \brief Build a new OpenMP 'shared' clause.
1549 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001550 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001551 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001552 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1553 SourceLocation StartLoc,
1554 SourceLocation LParenLoc,
1555 SourceLocation EndLoc) {
1556 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1557 EndLoc);
1558 }
1559
Alexey Bataevc5e02582014-06-16 07:08:35 +00001560 /// \brief Build a new OpenMP 'reduction' clause.
1561 ///
1562 /// By default, performs semantic analysis to build the new statement.
1563 /// Subclasses may override this routine to provide different behavior.
1564 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1565 SourceLocation StartLoc,
1566 SourceLocation LParenLoc,
1567 SourceLocation ColonLoc,
1568 SourceLocation EndLoc,
1569 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001570 const DeclarationNameInfo &ReductionId,
1571 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001572 return getSema().ActOnOpenMPReductionClause(
1573 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001574 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001575 }
1576
Alexander Musman8dba6642014-04-22 13:09:42 +00001577 /// \brief Build a new OpenMP 'linear' clause.
1578 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001579 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1582 SourceLocation StartLoc,
1583 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001584 OpenMPLinearClauseKind Modifier,
1585 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001586 SourceLocation ColonLoc,
1587 SourceLocation EndLoc) {
1588 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001589 Modifier, ModifierLoc, ColonLoc,
1590 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001591 }
1592
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001593 /// \brief Build a new OpenMP 'aligned' clause.
1594 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001595 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001596 /// Subclasses may override this routine to provide different behavior.
1597 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1598 SourceLocation StartLoc,
1599 SourceLocation LParenLoc,
1600 SourceLocation ColonLoc,
1601 SourceLocation EndLoc) {
1602 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1603 LParenLoc, ColonLoc, EndLoc);
1604 }
1605
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001606 /// \brief Build a new OpenMP 'copyin' clause.
1607 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001608 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001609 /// Subclasses may override this routine to provide different behavior.
1610 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1611 SourceLocation StartLoc,
1612 SourceLocation LParenLoc,
1613 SourceLocation EndLoc) {
1614 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1615 EndLoc);
1616 }
1617
Alexey Bataevbae9a792014-06-27 10:37:06 +00001618 /// \brief Build a new OpenMP 'copyprivate' clause.
1619 ///
1620 /// By default, performs semantic analysis to build the new OpenMP clause.
1621 /// Subclasses may override this routine to provide different behavior.
1622 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1623 SourceLocation StartLoc,
1624 SourceLocation LParenLoc,
1625 SourceLocation EndLoc) {
1626 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1627 EndLoc);
1628 }
1629
Alexey Bataev6125da92014-07-21 11:26:11 +00001630 /// \brief Build a new OpenMP 'flush' pseudo clause.
1631 ///
1632 /// By default, performs semantic analysis to build the new OpenMP clause.
1633 /// Subclasses may override this routine to provide different behavior.
1634 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1635 SourceLocation StartLoc,
1636 SourceLocation LParenLoc,
1637 SourceLocation EndLoc) {
1638 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1639 EndLoc);
1640 }
1641
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001642 /// \brief Build a new OpenMP 'depend' pseudo clause.
1643 ///
1644 /// By default, performs semantic analysis to build the new OpenMP clause.
1645 /// Subclasses may override this routine to provide different behavior.
1646 OMPClause *
1647 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1648 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1649 SourceLocation StartLoc, SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
1651 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1652 StartLoc, LParenLoc, EndLoc);
1653 }
1654
Michael Wonge710d542015-08-07 16:16:36 +00001655 /// \brief Build a new OpenMP 'device' clause.
1656 ///
1657 /// By default, performs semantic analysis to build the new statement.
1658 /// Subclasses may override this routine to provide different behavior.
1659 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1660 SourceLocation LParenLoc,
1661 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001662 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001663 EndLoc);
1664 }
1665
Kelvin Li0bff7af2015-11-23 05:32:03 +00001666 /// \brief Build a new OpenMP 'map' clause.
1667 ///
1668 /// By default, performs semantic analysis to build the new OpenMP clause.
1669 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001670 OMPClause *
1671 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1672 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1673 SourceLocation MapLoc, SourceLocation ColonLoc,
1674 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1675 SourceLocation LParenLoc, SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1677 IsMapTypeImplicit, MapLoc, ColonLoc,
1678 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001679 }
1680
Kelvin Li099bb8c2015-11-24 20:50:12 +00001681 /// \brief Build a new OpenMP 'num_teams' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1689 EndLoc);
1690 }
1691
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001692 /// \brief Build a new OpenMP 'thread_limit' 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 *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1697 SourceLocation StartLoc,
1698 SourceLocation LParenLoc,
1699 SourceLocation EndLoc) {
1700 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1701 LParenLoc, EndLoc);
1702 }
1703
Alexey Bataeva0569352015-12-01 10:17:31 +00001704 /// \brief Build a new OpenMP 'priority' clause.
1705 ///
1706 /// By default, performs semantic analysis to build the new statement.
1707 /// Subclasses may override this routine to provide different behavior.
1708 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1709 SourceLocation LParenLoc,
1710 SourceLocation EndLoc) {
1711 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1712 EndLoc);
1713 }
1714
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001715 /// \brief Build a new OpenMP 'grainsize' clause.
1716 ///
1717 /// By default, performs semantic analysis to build the new statement.
1718 /// Subclasses may override this routine to provide different behavior.
1719 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1720 SourceLocation LParenLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1723 EndLoc);
1724 }
1725
Alexey Bataev382967a2015-12-08 12:06:20 +00001726 /// \brief Build a new OpenMP 'num_tasks' clause.
1727 ///
1728 /// By default, performs semantic analysis to build the new statement.
1729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1731 SourceLocation LParenLoc,
1732 SourceLocation EndLoc) {
1733 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1734 EndLoc);
1735 }
1736
Alexey Bataev28c75412015-12-15 08:19:24 +00001737 /// \brief Build a new OpenMP 'hint' clause.
1738 ///
1739 /// By default, performs semantic analysis to build the new statement.
1740 /// Subclasses may override this routine to provide different behavior.
1741 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1742 SourceLocation LParenLoc,
1743 SourceLocation EndLoc) {
1744 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1745 }
1746
Carlo Bertollib4adf552016-01-15 18:50:31 +00001747 /// \brief Build a new OpenMP 'dist_schedule' clause.
1748 ///
1749 /// By default, performs semantic analysis to build the new OpenMP clause.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *
1752 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1753 Expr *ChunkSize, SourceLocation StartLoc,
1754 SourceLocation LParenLoc, SourceLocation KindLoc,
1755 SourceLocation CommaLoc, SourceLocation EndLoc) {
1756 return getSema().ActOnOpenMPDistScheduleClause(
1757 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1758 }
1759
Samuel Antao661c0902016-05-26 17:39:58 +00001760 /// \brief Build a new OpenMP 'to' clause.
1761 ///
1762 /// By default, performs semantic analysis to build the new statement.
1763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1769 }
1770
Samuel Antaoec172c62016-05-26 17:49:04 +00001771 /// \brief Build a new OpenMP 'from' clause.
1772 ///
1773 /// By default, performs semantic analysis to build the new statement.
1774 /// Subclasses may override this routine to provide different behavior.
1775 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1776 SourceLocation StartLoc,
1777 SourceLocation LParenLoc,
1778 SourceLocation EndLoc) {
1779 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1780 EndLoc);
1781 }
1782
James Dennett2a4d13c2012-06-15 07:13:21 +00001783 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001784 ///
1785 /// By default, performs semantic analysis to build the new statement.
1786 /// Subclasses may override this routine to provide different behavior.
1787 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1788 Expr *object) {
1789 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1790 }
1791
James Dennett2a4d13c2012-06-15 07:13:21 +00001792 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001793 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001794 /// By default, performs semantic analysis to build the new statement.
1795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001796 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001797 Expr *Object, Stmt *Body) {
1798 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001799 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001800
James Dennett2a4d13c2012-06-15 07:13:21 +00001801 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001802 ///
1803 /// By default, performs semantic analysis to build the new statement.
1804 /// Subclasses may override this routine to provide different behavior.
1805 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1806 Stmt *Body) {
1807 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1808 }
John McCall53848232011-07-27 01:07:15 +00001809
Douglas Gregorf68a5082010-04-22 23:10:45 +00001810 /// \brief Build a new Objective-C fast enumeration statement.
1811 ///
1812 /// By default, performs semantic analysis to build the new statement.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001815 Stmt *Element,
1816 Expr *Collection,
1817 SourceLocation RParenLoc,
1818 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001819 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001820 Element,
John McCallb268a282010-08-23 23:25:46 +00001821 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001822 RParenLoc);
1823 if (ForEachStmt.isInvalid())
1824 return StmtError();
1825
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001826 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001828
Douglas Gregorebe10102009-08-20 07:17:43 +00001829 /// \brief Build a new C++ exception declaration.
1830 ///
1831 /// By default, performs semantic analysis to build the new decaration.
1832 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001833 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001834 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001835 SourceLocation StartLoc,
1836 SourceLocation IdLoc,
1837 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001838 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001839 StartLoc, IdLoc, Id);
1840 if (Var)
1841 getSema().CurContext->addDecl(Var);
1842 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001843 }
1844
1845 /// \brief Build a new C++ catch statement.
1846 ///
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001850 VarDecl *ExceptionDecl,
1851 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001852 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1853 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregorebe10102009-08-20 07:17:43 +00001856 /// \brief Build a new C++ try statement.
1857 ///
1858 /// By default, performs semantic analysis to build the new statement.
1859 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001860 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1861 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001862 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001863 }
Mike Stump11289f42009-09-09 15:08:12 +00001864
Richard Smith02e85f32011-04-14 22:09:26 +00001865 /// \brief Build a new C++0x range-based for statement.
1866 ///
1867 /// By default, performs semantic analysis to build the new statement.
1868 /// Subclasses may override this routine to provide different behavior.
1869 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001870 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001871 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001872 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001873 Expr *Cond, Expr *Inc,
1874 Stmt *LoopVar,
1875 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001876 // If we've just learned that the range is actually an Objective-C
1877 // collection, treat this as an Objective-C fast enumeration loop.
1878 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1879 if (RangeStmt->isSingleDecl()) {
1880 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001881 if (RangeVar->isInvalidDecl())
1882 return StmtError();
1883
Douglas Gregorf7106af2013-04-08 18:40:13 +00001884 Expr *RangeExpr = RangeVar->getInit();
1885 if (!RangeExpr->isTypeDependent() &&
1886 RangeExpr->getType()->isObjCObjectPointerType())
1887 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1888 RParenLoc);
1889 }
1890 }
1891 }
1892
Richard Smithcfd53b42015-10-22 06:13:50 +00001893 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001894 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001895 Cond, Inc, LoopVar, RParenLoc,
1896 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001897 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001898
1899 /// \brief Build a new C++0x range-based for statement.
1900 ///
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001903 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001904 bool IsIfExists,
1905 NestedNameSpecifierLoc QualifierLoc,
1906 DeclarationNameInfo NameInfo,
1907 Stmt *Nested) {
1908 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1909 QualifierLoc, NameInfo, Nested);
1910 }
1911
Richard Smith02e85f32011-04-14 22:09:26 +00001912 /// \brief Attach body to a C++0x range-based for statement.
1913 ///
1914 /// By default, performs semantic analysis to finish the new statement.
1915 /// Subclasses may override this routine to provide different behavior.
1916 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1917 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001919
David Majnemerfad8f482013-10-15 09:33:02 +00001920 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001921 Stmt *TryBlock, Stmt *Handler) {
1922 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001923 }
1924
David Majnemerfad8f482013-10-15 09:33:02 +00001925 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001926 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001927 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001928 }
1929
David Majnemerfad8f482013-10-15 09:33:02 +00001930 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001931 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001932 }
1933
Alexey Bataevec474782014-10-09 08:45:04 +00001934 /// \brief Build a new predefined expression.
1935 ///
1936 /// By default, performs semantic analysis to build the new expression.
1937 /// Subclasses may override this routine to provide different behavior.
1938 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1939 PredefinedExpr::IdentType IT) {
1940 return getSema().BuildPredefinedExpr(Loc, IT);
1941 }
1942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new expression that references a declaration.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001948 LookupResult &R,
1949 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001950 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1951 }
1952
1953
1954 /// \brief Build a new expression that references a declaration.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001958 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001959 ValueDecl *VD,
1960 const DeclarationNameInfo &NameInfo,
1961 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001962 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001963 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001964
1965 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001966
1967 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
Mike Stump11289f42009-09-09 15:08:12 +00001969
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001971 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001976 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 }
1978
Douglas Gregorad8a3362009-09-04 17:36:40 +00001979 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001980 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001983 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001984 SourceLocation OperatorLoc,
1985 bool isArrow,
1986 CXXScopeSpec &SS,
1987 TypeSourceInfo *ScopeType,
1988 SourceLocation CCLoc,
1989 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001990 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001993 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001997 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001998 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001999 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 }
Mike Stump11289f42009-09-09 15:08:12 +00002001
Douglas Gregor882211c2010-04-28 22:16:22 +00002002 /// \brief Build a new builtin offsetof expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002006 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002007 TypeSourceInfo *Type,
2008 ArrayRef<Sema::OffsetOfComponent> Components,
2009 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002010 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002011 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002013
2014 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002015 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002016 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// By default, performs semantic analysis to build the new expression.
2018 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002019 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2020 SourceLocation OpLoc,
2021 UnaryExprOrTypeTrait ExprKind,
2022 SourceRange R) {
2023 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 }
2025
Peter Collingbournee190dee2011-03-11 19:24:49 +00002026 /// \brief Build a new sizeof, alignof or vec step expression with an
2027 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002031 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2032 UnaryExprOrTypeTrait ExprKind,
2033 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002035 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002038
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002039 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002048 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002050 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002051 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 RBracketLoc);
2053 }
2054
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002055 /// \brief Build a new array section expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2060 Expr *LowerBound,
2061 SourceLocation ColonLoc, Expr *Length,
2062 SourceLocation RBracketLoc) {
2063 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2064 ColonLoc, Length, RBracketLoc);
2065 }
2066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002073 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002074 Expr *ExecConfig = nullptr) {
2075 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002076 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 }
2078
2079 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002080 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002084 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002085 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002086 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002087 const DeclarationNameInfo &MemberNameInfo,
2088 ValueDecl *Member,
2089 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002090 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002091 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002092 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2093 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002094 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002095 // We have a reference to an unnamed field. This is always the
2096 // base of an anonymous struct/union member access, i.e. the
2097 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002098 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002099 assert(Member->getType()->isRecordType() &&
2100 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002101
Richard Smithcab9a7d2011-10-26 19:06:56 +00002102 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002103 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002104 QualifierLoc.getNestedNameSpecifier(),
2105 FoundDecl, Member);
2106 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002107 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002108 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002109 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002110 MemberExpr *ME = new (getSema().Context)
2111 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2112 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002113 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002114 }
Mike Stump11289f42009-09-09 15:08:12 +00002115
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002116 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002117 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002118
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002119 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002120 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002121
John McCall16df1e52010-03-30 21:47:33 +00002122 // FIXME: this involves duplicating earlier analysis in a lot of
2123 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002124 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002125 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002126 R.resolveKind();
2127
John McCallb268a282010-08-23 23:25:46 +00002128 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002129 SS, TemplateKWLoc,
2130 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002131 R, ExplicitTemplateArgs,
2132 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 }
Mike Stump11289f42009-09-09 15:08:12 +00002134
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002139 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002140 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002141 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002142 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002146 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002150 SourceLocation QuestionLoc,
2151 Expr *LHS,
2152 SourceLocation ColonLoc,
2153 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002154 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2155 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002163 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002165 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002166 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002167 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 }
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002171 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002175 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002177 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002178 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002179 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002183 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002186 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 SourceLocation OpLoc,
2188 SourceLocation AccessorLoc,
2189 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002190
John McCall10eae182009-11-30 22:42:35 +00002191 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002192 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002193 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002194 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002195 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002196 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002197 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002198 /* TemplateArgs */ nullptr,
2199 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002203 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002206 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002207 MultiExprArg Inits,
2208 SourceLocation RBraceLoc,
2209 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002210 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002211 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002212 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002213 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002214
Douglas Gregord3d93062009-11-09 17:16:50 +00002215 // Patch in the result type we were given, which may have been computed
2216 // when the initial InitListExpr was built.
2217 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2218 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002219 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 }
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002223 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 MultiExprArg ArrayExprs,
2228 SourceLocation EqualOrColonLoc,
2229 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002230 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002233 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002236
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002237 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 }
Mike Stump11289f42009-09-09 15:08:12 +00002239
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002241 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// By default, builds the implicit value initialization without performing
2243 /// any semantic analysis. Subclasses may override this routine to provide
2244 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002245 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002246 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002253 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002254 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002255 SourceLocation RParenLoc) {
2256 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002258 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 }
2260
2261 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002265 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002266 MultiExprArg SubExprs,
2267 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002268 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002272 ///
2273 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// rather than attempting to map the label statement itself.
2275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002276 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002277 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002278 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 }
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002285 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002286 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002288 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// \brief Build a new __builtin_choose_expr expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002296 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 SourceLocation RParenLoc) {
2298 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002299 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 RParenLoc);
2301 }
Mike Stump11289f42009-09-09 15:08:12 +00002302
Peter Collingbourne91147592011-04-15 00:35:48 +00002303 /// \brief Build a new generic selection expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
2307 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2308 SourceLocation DefaultLoc,
2309 SourceLocation RParenLoc,
2310 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002311 ArrayRef<TypeSourceInfo *> Types,
2312 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002313 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002314 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002315 }
2316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new overloaded operator call expression.
2318 ///
2319 /// By default, performs semantic analysis to build the new expression.
2320 /// The semantic analysis provides the behavior of template instantiation,
2321 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002322 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// argument-dependent lookup, etc. Subclasses may override this routine to
2324 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002325 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002327 Expr *Callee,
2328 Expr *First,
2329 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002330
2331 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 /// reinterpret_cast.
2333 ///
2334 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002335 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002337 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 Stmt::StmtClass Class,
2339 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002340 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 SourceLocation RAngleLoc,
2342 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002343 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 SourceLocation RParenLoc) {
2345 switch (Class) {
2346 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002347 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002348 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002349 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002350
2351 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002352 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002353 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002354 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002355
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002357 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002358 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002359 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002361
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002363 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002364 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002365 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002366
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002368 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 /// \brief Build a new C++ static_cast expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002376 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002378 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 SourceLocation RAngleLoc,
2380 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002381 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002383 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002384 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002385 SourceRange(LAngleLoc, RAngleLoc),
2386 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 }
2388
2389 /// \brief Build a new C++ dynamic_cast expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002395 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 SourceLocation RAngleLoc,
2397 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002398 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002400 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002401 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002402 SourceRange(LAngleLoc, RAngleLoc),
2403 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new C++ reinterpret_cast expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002412 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002413 SourceLocation RAngleLoc,
2414 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002415 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002417 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002418 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002419 SourceRange(LAngleLoc, RAngleLoc),
2420 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
2422
2423 /// \brief Build a new C++ const_cast expression.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 SourceLocation RAngleLoc,
2431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002436 SourceRange(LAngleLoc, RAngleLoc),
2437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 }
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// \brief Build a new C++ functional-style cast expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002444 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2445 SourceLocation LParenLoc,
2446 Expr *Sub,
2447 SourceLocation RParenLoc) {
2448 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002449 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 RParenLoc);
2451 }
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 /// \brief Build a new C++ typeid(type) expression.
2454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002458 SourceLocation TypeidLoc,
2459 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002461 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002462 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
Mike Stump11289f42009-09-09 15:08:12 +00002464
Francois Pichet9f4f2072010-09-08 12:20:18 +00002465
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 /// \brief Build a new C++ typeid(expr) expression.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002470 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002471 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002472 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002474 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002475 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002476 }
2477
Francois Pichet9f4f2072010-09-08 12:20:18 +00002478 /// \brief Build a new C++ __uuidof(type) expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
2482 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2483 SourceLocation TypeidLoc,
2484 TypeSourceInfo *Operand,
2485 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002486 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002487 RParenLoc);
2488 }
2489
2490 /// \brief Build a new C++ __uuidof(expr) expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2495 SourceLocation TypeidLoc,
2496 Expr *Operand,
2497 SourceLocation RParenLoc) {
2498 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2499 RParenLoc);
2500 }
2501
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 /// \brief Build a new C++ "this" expression.
2503 ///
2504 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002505 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002507 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002508 QualType ThisType,
2509 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002510 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002511 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 }
2513
2514 /// \brief Build a new C++ throw expression.
2515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002518 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2519 bool IsThrownVariableInScope) {
2520 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 }
2522
2523 /// \brief Build a new C++ default-argument expression.
2524 ///
2525 /// By default, builds a new default-argument expression, which does not
2526 /// require any semantic analysis. Subclasses may override this routine to
2527 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002528 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002529 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002530 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 }
2532
Richard Smith852c9db2013-04-20 22:23:05 +00002533 /// \brief Build a new C++11 default-initialization expression.
2534 ///
2535 /// By default, builds a new default field initialization expression, which
2536 /// does not require any semantic analysis. Subclasses may override this
2537 /// routine to provide different behavior.
2538 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2539 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002540 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002541 }
2542
Douglas Gregora16548e2009-08-11 05:31:07 +00002543 /// \brief Build a new C++ zero-initialization expression.
2544 ///
2545 /// By default, performs semantic analysis to build the new expression.
2546 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002547 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2548 SourceLocation LParenLoc,
2549 SourceLocation RParenLoc) {
2550 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002551 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 }
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 /// \brief Build a new C++ "new" expression.
2555 ///
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002558 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002559 bool UseGlobal,
2560 SourceLocation PlacementLParen,
2561 MultiExprArg PlacementArgs,
2562 SourceLocation PlacementRParen,
2563 SourceRange TypeIdParens,
2564 QualType AllocatedType,
2565 TypeSourceInfo *AllocatedTypeInfo,
2566 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002567 SourceRange DirectInitRange,
2568 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002569 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002571 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002573 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002574 AllocatedType,
2575 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002576 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002577 DirectInitRange,
2578 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 }
Mike Stump11289f42009-09-09 15:08:12 +00002580
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 /// \brief Build a new C++ "delete" expression.
2582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 bool IsGlobalDelete,
2587 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002588 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002590 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592
Douglas Gregor29c42f22012-02-24 07:38:34 +00002593 /// \brief Build a new type trait expression.
2594 ///
2595 /// By default, performs semantic analysis to build the new expression.
2596 /// Subclasses may override this routine to provide different behavior.
2597 ExprResult RebuildTypeTrait(TypeTrait Trait,
2598 SourceLocation StartLoc,
2599 ArrayRef<TypeSourceInfo *> Args,
2600 SourceLocation RParenLoc) {
2601 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002603
John Wiegley6242b6a2011-04-28 00:16:57 +00002604 /// \brief Build a new array type trait expression.
2605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
2608 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2609 SourceLocation StartLoc,
2610 TypeSourceInfo *TSInfo,
2611 Expr *DimExpr,
2612 SourceLocation RParenLoc) {
2613 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2614 }
2615
John Wiegleyf9f65842011-04-25 06:54:41 +00002616 /// \brief Build a new expression trait expression.
2617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
2620 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2621 SourceLocation StartLoc,
2622 Expr *Queried,
2623 SourceLocation RParenLoc) {
2624 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2625 }
2626
Mike Stump11289f42009-09-09 15:08:12 +00002627 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 /// expression.
2629 ///
2630 /// By default, performs semantic analysis to build the new expression.
2631 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002632 ExprResult RebuildDependentScopeDeclRefExpr(
2633 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002634 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002635 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002636 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002637 bool IsAddressOfOperand,
2638 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002640 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002641
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002642 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002643 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2644 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002645
Reid Kleckner32506ed2014-06-12 23:03:48 +00002646 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002647 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002648 }
2649
2650 /// \brief Build a new template-id expression.
2651 ///
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002654 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002655 SourceLocation TemplateKWLoc,
2656 LookupResult &R,
2657 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002658 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002659 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2660 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002661 }
2662
2663 /// \brief Build a new object-construction expression.
2664 ///
2665 /// By default, performs semantic analysis to build the new expression.
2666 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002667 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002668 SourceLocation Loc,
2669 CXXConstructorDecl *Constructor,
2670 bool IsElidable,
2671 MultiExprArg Args,
2672 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002673 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002674 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002675 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002676 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002677 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002678 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002679 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002680 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002681 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002682
Richard Smithc83bf822016-06-10 00:58:19 +00002683 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002684 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002685 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002686 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002687 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002688 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002689 RequiresZeroInit, ConstructKind,
2690 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 }
2692
2693 /// \brief Build a new object-construction expression.
2694 ///
2695 /// By default, performs semantic analysis to build the new expression.
2696 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002697 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2698 SourceLocation LParenLoc,
2699 MultiExprArg Args,
2700 SourceLocation RParenLoc) {
2701 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002702 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002703 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 RParenLoc);
2705 }
2706
2707 /// \brief Build a new object-construction expression.
2708 ///
2709 /// By default, performs semantic analysis to build the new expression.
2710 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002711 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2712 SourceLocation LParenLoc,
2713 MultiExprArg Args,
2714 SourceLocation RParenLoc) {
2715 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002717 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002718 RParenLoc);
2719 }
Mike Stump11289f42009-09-09 15:08:12 +00002720
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 /// \brief Build a new member reference expression.
2722 ///
2723 /// By default, performs semantic analysis to build the new expression.
2724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002725 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002726 QualType BaseType,
2727 bool IsArrow,
2728 SourceLocation OperatorLoc,
2729 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002730 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002731 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002732 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002733 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002734 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002735 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002736
John McCallb268a282010-08-23 23:25:46 +00002737 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002738 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002739 SS, TemplateKWLoc,
2740 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002741 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002742 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002743 }
2744
John McCall10eae182009-11-30 22:42:35 +00002745 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002749 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2750 SourceLocation OperatorLoc,
2751 bool IsArrow,
2752 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002753 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002754 NamedDecl *FirstQualifierInScope,
2755 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002756 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002757 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002758 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCallb268a282010-08-23 23:25:46 +00002760 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002761 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002762 SS, TemplateKWLoc,
2763 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002764 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002765 }
Mike Stump11289f42009-09-09 15:08:12 +00002766
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002767 /// \brief Build a new noexcept expression.
2768 ///
2769 /// By default, performs semantic analysis to build the new expression.
2770 /// Subclasses may override this routine to provide different behavior.
2771 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2772 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2773 }
2774
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002775 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002776 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2777 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002778 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002779 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002780 Optional<unsigned> Length,
2781 ArrayRef<TemplateArgument> PartialArgs) {
2782 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2783 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002784 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002785
Patrick Beard0caa3942012-04-19 00:25:12 +00002786 /// \brief Build a new Objective-C boxed expression.
2787 ///
2788 /// By default, performs semantic analysis to build the new expression.
2789 /// Subclasses may override this routine to provide different behavior.
2790 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2791 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Ted Kremeneke65b0862012-03-06 20:05:56 +00002794 /// \brief Build a new Objective-C array literal.
2795 ///
2796 /// By default, performs semantic analysis to build the new expression.
2797 /// Subclasses may override this routine to provide different behavior.
2798 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2799 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002800 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002801 MultiExprArg(Elements, NumElements));
2802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002803
2804 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002805 Expr *Base, Expr *Key,
2806 ObjCMethodDecl *getterMethod,
2807 ObjCMethodDecl *setterMethod) {
2808 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2809 getterMethod, setterMethod);
2810 }
2811
2812 /// \brief Build a new Objective-C dictionary literal.
2813 ///
2814 /// By default, performs semantic analysis to build the new expression.
2815 /// Subclasses may override this routine to provide different behavior.
2816 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002817 MutableArrayRef<ObjCDictionaryElement> Elements) {
2818 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
James Dennett2a4d13c2012-06-15 07:13:21 +00002821 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002822 ///
2823 /// By default, performs semantic analysis to build the new expression.
2824 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002825 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002826 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002828 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002829 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002830
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002831 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002832 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002833 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002834 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002835 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002836 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002837 MultiExprArg Args,
2838 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002839 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2840 ReceiverTypeInfo->getType(),
2841 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002842 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002843 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002844 }
2845
2846 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002847 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002848 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002849 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002850 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002851 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002852 MultiExprArg Args,
2853 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002854 return SemaRef.BuildInstanceMessage(Receiver,
2855 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002856 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002857 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002858 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002859 }
2860
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002861 /// \brief Build a new Objective-C instance/class message to 'super'.
2862 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2863 Selector Sel,
2864 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002865 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002866 ObjCMethodDecl *Method,
2867 SourceLocation LBracLoc,
2868 MultiExprArg Args,
2869 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002870 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002871 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002872 SuperLoc,
2873 Sel, Method, LBracLoc, SelectorLocs,
2874 RBracLoc, Args)
2875 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002876 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002877 SuperLoc,
2878 Sel, Method, LBracLoc, SelectorLocs,
2879 RBracLoc, Args);
2880
2881
2882 }
2883
Douglas Gregord51d90d2010-04-26 20:11:03 +00002884 /// \brief Build a new Objective-C ivar reference expression.
2885 ///
2886 /// By default, performs semantic analysis to build the new expression.
2887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002888 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002889 SourceLocation IvarLoc,
2890 bool IsArrow, bool IsFreeIvar) {
2891 // FIXME: We lose track of the IsFreeIvar bit.
2892 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002893 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2894 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002895 /*FIXME:*/IvarLoc, IsArrow,
2896 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002897 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002898 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002899 /*TemplateArgs=*/nullptr,
2900 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002901 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002902
2903 /// \brief Build a new Objective-C property reference expression.
2904 ///
2905 /// By default, performs semantic analysis to build the new expression.
2906 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002907 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002908 ObjCPropertyDecl *Property,
2909 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002910 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002911 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2912 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2913 /*FIXME:*/PropertyLoc,
2914 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002915 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002916 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002917 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002918 /*TemplateArgs=*/nullptr,
2919 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
John McCallb7bd14f2010-12-02 01:19:52 +00002922 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002923 ///
2924 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002925 /// Subclasses may override this routine to provide different behavior.
2926 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2927 ObjCMethodDecl *Getter,
2928 ObjCMethodDecl *Setter,
2929 SourceLocation PropertyLoc) {
2930 // Since these expressions can only be value-dependent, we do not
2931 // need to perform semantic analysis again.
2932 return Owned(
2933 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2934 VK_LValue, OK_ObjCProperty,
2935 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002936 }
2937
Douglas Gregord51d90d2010-04-26 20:11:03 +00002938 /// \brief Build a new Objective-C "isa" expression.
2939 ///
2940 /// By default, performs semantic analysis to build the new expression.
2941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002942 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002943 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002944 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002945 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2946 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002947 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002948 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002949 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002950 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002951 /*TemplateArgs=*/nullptr,
2952 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregora16548e2009-08-11 05:31:07 +00002955 /// \brief Build a new shuffle vector expression.
2956 ///
2957 /// By default, performs semantic analysis to build the new expression.
2958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002959 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002960 MultiExprArg SubExprs,
2961 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002962 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002963 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002964 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2965 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2966 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002967 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregora16548e2009-08-11 05:31:07 +00002969 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002970 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002971 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2972 SemaRef.Context.BuiltinFnTy,
2973 VK_RValue, BuiltinLoc);
2974 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2975 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002976 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002977
2978 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002979 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002980 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002981 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregora16548e2009-08-11 05:31:07 +00002983 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002984 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002985 }
John McCall31f82722010-11-12 08:19:04 +00002986
Hal Finkelc4d7c822013-09-18 03:29:45 +00002987 /// \brief Build a new convert vector expression.
2988 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2989 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2990 SourceLocation RParenLoc) {
2991 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2992 BuiltinLoc, RParenLoc);
2993 }
2994
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002995 /// \brief Build a new template argument pack expansion.
2996 ///
2997 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002998 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999 /// different behavior.
3000 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003001 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003002 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003004 case TemplateArgument::Expression: {
3005 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003006 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3007 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003008 if (Result.isInvalid())
3009 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor98318c22011-01-03 21:37:45 +00003011 return TemplateArgumentLoc(Result.get(), Result.get());
3012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003015 return TemplateArgumentLoc(TemplateArgument(
3016 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003017 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003018 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003019 Pattern.getTemplateNameLoc(),
3020 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003022 case TemplateArgument::Null:
3023 case TemplateArgument::Integral:
3024 case TemplateArgument::Declaration:
3025 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003026 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003027 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003028 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003029
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003030 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003031 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003033 EllipsisLoc,
3034 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003035 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3036 Expansion);
3037 break;
3038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003040 return TemplateArgumentLoc();
3041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 /// \brief Build a new expression pack expansion.
3044 ///
3045 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003046 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003047 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003048 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003049 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003050 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003051 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003052
Richard Smith0f0af192014-11-08 05:07:16 +00003053 /// \brief Build a new C++1z fold-expression.
3054 ///
3055 /// By default, performs semantic analysis in order to build a new fold
3056 /// expression.
3057 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3058 BinaryOperatorKind Operator,
3059 SourceLocation EllipsisLoc, Expr *RHS,
3060 SourceLocation RParenLoc) {
3061 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3062 RHS, RParenLoc);
3063 }
3064
3065 /// \brief Build an empty C++1z fold-expression with the given operator.
3066 ///
3067 /// By default, produces the fallback value for the fold-expression, or
3068 /// produce an error if there is no fallback value.
3069 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3070 BinaryOperatorKind Operator) {
3071 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3072 }
3073
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003074 /// \brief Build a new atomic operation expression.
3075 ///
3076 /// By default, performs semantic analysis to build the new expression.
3077 /// Subclasses may override this routine to provide different behavior.
3078 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3079 MultiExprArg SubExprs,
3080 QualType RetTy,
3081 AtomicExpr::AtomicOp Op,
3082 SourceLocation RParenLoc) {
3083 // Just create the expression; there is not any interesting semantic
3084 // analysis here because we can't actually build an AtomicExpr until
3085 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003086 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003087 RParenLoc);
3088 }
3089
John McCall31f82722010-11-12 08:19:04 +00003090private:
Douglas Gregor14454802011-02-25 02:25:35 +00003091 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3092 QualType ObjectType,
3093 NamedDecl *FirstQualifierInScope,
3094 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003095
3096 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3097 QualType ObjectType,
3098 NamedDecl *FirstQualifierInScope,
3099 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003100
3101 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3102 NamedDecl *FirstQualifierInScope,
3103 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104};
Douglas Gregora16548e2009-08-11 05:31:07 +00003105
Douglas Gregorebe10102009-08-20 07:17:43 +00003106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003107StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003108 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003109 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003110
Douglas Gregorebe10102009-08-20 07:17:43 +00003111 switch (S->getStmtClass()) {
3112 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003113
Douglas Gregorebe10102009-08-20 07:17:43 +00003114 // Transform individual statement nodes
3115#define STMT(Node, Parent) \
3116 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003117#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003118#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003119#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 // Transform expressions by calling TransformExpr.
3122#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003123#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003124#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003125#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 {
John McCalldadc5752010-08-24 06:29:42 +00003127 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003130
Richard Smith945f8d32013-01-14 22:39:08 +00003131 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 }
Mike Stump11289f42009-09-09 15:08:12 +00003133 }
3134
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003135 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003136}
Mike Stump11289f42009-09-09 15:08:12 +00003137
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003138template<typename Derived>
3139OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3140 if (!S)
3141 return S;
3142
3143 switch (S->getClauseKind()) {
3144 default: break;
3145 // Transform individual clause nodes
3146#define OPENMP_CLAUSE(Name, Class) \
3147 case OMPC_ ## Name : \
3148 return getDerived().Transform ## Class(cast<Class>(S));
3149#include "clang/Basic/OpenMPKinds.def"
3150 }
3151
3152 return S;
3153}
3154
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregore922c772009-08-04 22:27:00 +00003156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003157ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003158 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003159 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003160
3161 switch (E->getStmtClass()) {
3162 case Stmt::NoStmtClass: break;
3163#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003164#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003165#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003166 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003167#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003168 }
3169
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003170 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003171}
3172
3173template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003174ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003175 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003176 // Initializers are instantiated like expressions, except that various outer
3177 // layers are stripped.
3178 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003179 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003180
3181 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3182 Init = ExprTemp->getSubExpr();
3183
Richard Smithe6ca4752013-05-30 22:40:16 +00003184 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3185 Init = MTE->GetTemporaryExpr();
3186
Richard Smithd59b8322012-12-19 01:39:02 +00003187 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3188 Init = Binder->getSubExpr();
3189
3190 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3191 Init = ICE->getSubExprAsWritten();
3192
Richard Smithcc1b96d2013-06-12 22:31:48 +00003193 if (CXXStdInitializerListExpr *ILE =
3194 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003195 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003196
Richard Smithc6abd962014-07-25 01:12:44 +00003197 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003198 // InitListExprs. Other forms of copy-initialization will be a no-op if
3199 // the initializer is already the right type.
3200 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003201 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003202 return getDerived().TransformExpr(Init);
3203
3204 // Revert value-initialization back to empty parens.
3205 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3206 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003207 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003208 Parens.getEnd());
3209 }
3210
3211 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3212 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003213 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003214 SourceLocation());
3215
3216 // Revert initialization by constructor back to a parenthesized or braced list
3217 // of expressions. Any other form of initializer can just be reused directly.
3218 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003219 return getDerived().TransformExpr(Init);
3220
Richard Smithf8adcdc2014-07-17 05:12:35 +00003221 // If the initialization implicitly converted an initializer list to a
3222 // std::initializer_list object, unwrap the std::initializer_list too.
3223 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003224 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003225
Richard Smithd59b8322012-12-19 01:39:02 +00003226 SmallVector<Expr*, 8> NewArgs;
3227 bool ArgChanged = false;
3228 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003229 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003230 return ExprError();
3231
3232 // If this was list initialization, revert to list form.
3233 if (Construct->isListInitialization())
3234 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3235 Construct->getLocEnd(),
3236 Construct->getType());
3237
Richard Smithd59b8322012-12-19 01:39:02 +00003238 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003239 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003240 if (Parens.isInvalid()) {
3241 // This was a variable declaration's initialization for which no initializer
3242 // was specified.
3243 assert(NewArgs.empty() &&
3244 "no parens or braces but have direct init with arguments?");
3245 return ExprEmpty();
3246 }
Richard Smithd59b8322012-12-19 01:39:02 +00003247 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3248 Parens.getEnd());
3249}
3250
3251template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003252bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003253 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003254 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003255 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003256 bool *ArgChanged) {
3257 for (unsigned I = 0; I != NumInputs; ++I) {
3258 // If requested, drop call arguments that need to be dropped.
3259 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3260 if (ArgChanged)
3261 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregora3efea12011-01-03 19:04:46 +00003263 break;
3264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor968f23a2011-01-03 19:31:53 +00003266 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3267 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Chris Lattner01cf8db2011-07-20 06:58:45 +00003269 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003270 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3271 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003272
Douglas Gregor968f23a2011-01-03 19:31:53 +00003273 // Determine whether the set of unexpanded parameter packs can and should
3274 // be expanded.
3275 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003276 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003277 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3278 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003279 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3280 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003281 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003282 Expand, RetainExpansion,
3283 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor968f23a2011-01-03 19:31:53 +00003286 if (!Expand) {
3287 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003288 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003289 // expansion.
3290 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3291 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3292 if (OutPattern.isInvalid())
3293 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003294
3295 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003296 Expansion->getEllipsisLoc(),
3297 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003298 if (Out.isInvalid())
3299 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor968f23a2011-01-03 19:31:53 +00003301 if (ArgChanged)
3302 *ArgChanged = true;
3303 Outputs.push_back(Out.get());
3304 continue;
3305 }
John McCall542e7c62011-07-06 07:30:07 +00003306
3307 // Record right away that the argument was changed. This needs
3308 // to happen even if the array expands to nothing.
3309 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor968f23a2011-01-03 19:31:53 +00003311 // The transform has determined that we should perform an elementwise
3312 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003313 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003314 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3315 ExprResult Out = getDerived().TransformExpr(Pattern);
3316 if (Out.isInvalid())
3317 return true;
3318
Richard Smith9467be42014-06-06 17:33:35 +00003319 // FIXME: Can this happen? We should not try to expand the pack
3320 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003321 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003322 Out = getDerived().RebuildPackExpansion(
3323 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003324 if (Out.isInvalid())
3325 return true;
3326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor968f23a2011-01-03 19:31:53 +00003328 Outputs.push_back(Out.get());
3329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Richard Smith9467be42014-06-06 17:33:35 +00003331 // If we're supposed to retain a pack expansion, do so by temporarily
3332 // forgetting the partially-substituted parameter pack.
3333 if (RetainExpansion) {
3334 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3335
3336 ExprResult Out = getDerived().TransformExpr(Pattern);
3337 if (Out.isInvalid())
3338 return true;
3339
3340 Out = getDerived().RebuildPackExpansion(
3341 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3342 if (Out.isInvalid())
3343 return true;
3344
3345 Outputs.push_back(Out.get());
3346 }
3347
Douglas Gregor968f23a2011-01-03 19:31:53 +00003348 continue;
3349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Richard Smithd59b8322012-12-19 01:39:02 +00003351 ExprResult Result =
3352 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3353 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003354 if (Result.isInvalid())
3355 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003356
Douglas Gregora3efea12011-01-03 19:04:46 +00003357 if (Result.get() != Inputs[I] && ArgChanged)
3358 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
3360 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregora3efea12011-01-03 19:04:46 +00003363 return false;
3364}
3365
Richard Smith03a4aa32016-06-23 19:02:52 +00003366template <typename Derived>
3367Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3368 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3369 if (Var) {
3370 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3371 getDerived().TransformDefinition(Var->getLocation(), Var));
3372
3373 if (!ConditionVar)
3374 return Sema::ConditionError();
3375
3376 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3377 }
3378
3379 if (Expr) {
3380 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3381
3382 if (CondExpr.isInvalid())
3383 return Sema::ConditionError();
3384
3385 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3386 }
3387
3388 return Sema::ConditionResult();
3389}
3390
Douglas Gregora3efea12011-01-03 19:04:46 +00003391template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003392NestedNameSpecifierLoc
3393TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3394 NestedNameSpecifierLoc NNS,
3395 QualType ObjectType,
3396 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003397 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003398 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003399 Qualifier = Qualifier.getPrefix())
3400 Qualifiers.push_back(Qualifier);
3401
3402 CXXScopeSpec SS;
3403 while (!Qualifiers.empty()) {
3404 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3405 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor14454802011-02-25 02:25:35 +00003407 switch (QNNS->getKind()) {
3408 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003409 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003410 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003411 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003412 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003413 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003414 FirstQualifierInScope, false))
3415 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor14454802011-02-25 02:25:35 +00003417 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor14454802011-02-25 02:25:35 +00003419 case NestedNameSpecifier::Namespace: {
3420 NamespaceDecl *NS
3421 = cast_or_null<NamespaceDecl>(
3422 getDerived().TransformDecl(
3423 Q.getLocalBeginLoc(),
3424 QNNS->getAsNamespace()));
3425 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3426 break;
3427 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor14454802011-02-25 02:25:35 +00003429 case NestedNameSpecifier::NamespaceAlias: {
3430 NamespaceAliasDecl *Alias
3431 = cast_or_null<NamespaceAliasDecl>(
3432 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3433 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003434 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003435 Q.getLocalEndLoc());
3436 break;
3437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor14454802011-02-25 02:25:35 +00003439 case NestedNameSpecifier::Global:
3440 // There is no meaningful transformation that one could perform on the
3441 // global scope.
3442 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3443 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Nikola Smiljanic67860242014-09-26 00:28:20 +00003445 case NestedNameSpecifier::Super: {
3446 CXXRecordDecl *RD =
3447 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3448 SourceLocation(), QNNS->getAsRecordDecl()));
3449 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3450 break;
3451 }
3452
Douglas Gregor14454802011-02-25 02:25:35 +00003453 case NestedNameSpecifier::TypeSpecWithTemplate:
3454 case NestedNameSpecifier::TypeSpec: {
3455 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3456 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor14454802011-02-25 02:25:35 +00003458 if (!TL)
3459 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor14454802011-02-25 02:25:35 +00003461 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003462 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003463 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003464 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003465 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003466 if (TL.getType()->isEnumeralType())
3467 SemaRef.Diag(TL.getBeginLoc(),
3468 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003469 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3470 Q.getLocalEndLoc());
3471 break;
3472 }
Richard Trieude756fb2011-05-07 01:36:37 +00003473 // If the nested-name-specifier is an invalid type def, don't emit an
3474 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003475 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3476 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003477 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003478 << TL.getType() << SS.getRange();
3479 }
Douglas Gregor14454802011-02-25 02:25:35 +00003480 return NestedNameSpecifierLoc();
3481 }
Douglas Gregore16af532011-02-28 18:50:33 +00003482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregore16af532011-02-28 18:50:33 +00003484 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003485 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003486 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003488
Douglas Gregor14454802011-02-25 02:25:35 +00003489 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003490 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003491 !getDerived().AlwaysRebuild())
3492 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
3494 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003495 // nested-name-specifier, do so.
3496 if (SS.location_size() == NNS.getDataLength() &&
3497 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3498 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3499
3500 // Allocate new nested-name-specifier location information.
3501 return SS.getWithLocInContext(SemaRef.Context);
3502}
3503
3504template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003505DeclarationNameInfo
3506TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003507::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003508 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003509 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003510 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003511
3512 switch (Name.getNameKind()) {
3513 case DeclarationName::Identifier:
3514 case DeclarationName::ObjCZeroArgSelector:
3515 case DeclarationName::ObjCOneArgSelector:
3516 case DeclarationName::ObjCMultiArgSelector:
3517 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003518 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003519 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003520 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorf816bd72009-09-03 22:13:48 +00003522 case DeclarationName::CXXConstructorName:
3523 case DeclarationName::CXXDestructorName:
3524 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003525 TypeSourceInfo *NewTInfo;
3526 CanQualType NewCanTy;
3527 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003528 NewTInfo = getDerived().TransformType(OldTInfo);
3529 if (!NewTInfo)
3530 return DeclarationNameInfo();
3531 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003532 }
3533 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003534 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003535 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003536 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003537 if (NewT.isNull())
3538 return DeclarationNameInfo();
3539 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3540 }
Mike Stump11289f42009-09-09 15:08:12 +00003541
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003542 DeclarationName NewName
3543 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3544 NewCanTy);
3545 DeclarationNameInfo NewNameInfo(NameInfo);
3546 NewNameInfo.setName(NewName);
3547 NewNameInfo.setNamedTypeInfo(NewTInfo);
3548 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003549 }
Mike Stump11289f42009-09-09 15:08:12 +00003550 }
3551
David Blaikie83d382b2011-09-23 05:06:16 +00003552 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003553}
3554
3555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003556TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003557TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3558 TemplateName Name,
3559 SourceLocation NameLoc,
3560 QualType ObjectType,
3561 NamedDecl *FirstQualifierInScope) {
3562 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3563 TemplateDecl *Template = QTN->getTemplateDecl();
3564 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregor9db53502011-03-02 18:07:45 +00003566 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003567 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003568 Template));
3569 if (!TransTemplate)
3570 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregor9db53502011-03-02 18:07:45 +00003572 if (!getDerived().AlwaysRebuild() &&
3573 SS.getScopeRep() == QTN->getQualifier() &&
3574 TransTemplate == Template)
3575 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3578 TransTemplate);
3579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor9db53502011-03-02 18:07:45 +00003581 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3582 if (SS.getScopeRep()) {
3583 // These apply to the scope specifier, not the template.
3584 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003585 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003586 }
3587
Douglas Gregor9db53502011-03-02 18:07:45 +00003588 if (!getDerived().AlwaysRebuild() &&
3589 SS.getScopeRep() == DTN->getQualifier() &&
3590 ObjectType.isNull())
3591 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor9db53502011-03-02 18:07:45 +00003593 if (DTN->isIdentifier()) {
3594 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003595 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003596 NameLoc,
3597 ObjectType,
3598 FirstQualifierInScope);
3599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregor9db53502011-03-02 18:07:45 +00003601 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3602 ObjectType);
3603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor9db53502011-03-02 18:07:45 +00003605 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3606 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003607 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003608 Template));
3609 if (!TransTemplate)
3610 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor9db53502011-03-02 18:07:45 +00003612 if (!getDerived().AlwaysRebuild() &&
3613 TransTemplate == Template)
3614 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor9db53502011-03-02 18:07:45 +00003616 return TemplateName(TransTemplate);
3617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor9db53502011-03-02 18:07:45 +00003619 if (SubstTemplateTemplateParmPackStorage *SubstPack
3620 = Name.getAsSubstTemplateTemplateParmPack()) {
3621 TemplateTemplateParmDecl *TransParam
3622 = cast_or_null<TemplateTemplateParmDecl>(
3623 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3624 if (!TransParam)
3625 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor9db53502011-03-02 18:07:45 +00003627 if (!getDerived().AlwaysRebuild() &&
3628 TransParam == SubstPack->getParameterPack())
3629 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
3631 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003632 SubstPack->getArgumentPack());
3633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
Douglas Gregor9db53502011-03-02 18:07:45 +00003635 // These should be getting filtered out before they reach the AST.
3636 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003637}
3638
3639template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003640void TreeTransform<Derived>::InventTemplateArgumentLoc(
3641 const TemplateArgument &Arg,
3642 TemplateArgumentLoc &Output) {
3643 SourceLocation Loc = getDerived().getBaseLocation();
3644 switch (Arg.getKind()) {
3645 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003646 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003647 break;
3648
3649 case TemplateArgument::Type:
3650 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003651 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
John McCall0ad16662009-10-29 08:12:44 +00003653 break;
3654
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003655 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003656 case TemplateArgument::TemplateExpansion: {
3657 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003658 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003659 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3660 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3661 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3662 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor9d802122011-03-02 17:09:35 +00003664 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003665 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003666 Builder.getWithLocInContext(SemaRef.Context),
3667 Loc);
3668 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003669 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003670 Builder.getWithLocInContext(SemaRef.Context),
3671 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003673 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003674 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003675
John McCall0ad16662009-10-29 08:12:44 +00003676 case TemplateArgument::Expression:
3677 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3678 break;
3679
3680 case TemplateArgument::Declaration:
3681 case TemplateArgument::Integral:
3682 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003683 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003684 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003685 break;
3686 }
3687}
3688
3689template<typename Derived>
3690bool TreeTransform<Derived>::TransformTemplateArgument(
3691 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003692 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003693 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003694 switch (Arg.getKind()) {
3695 case TemplateArgument::Null:
3696 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003697 case TemplateArgument::Pack:
3698 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003699 case TemplateArgument::NullPtr:
3700 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003701
Douglas Gregore922c772009-08-04 22:27:00 +00003702 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003703 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003704 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003705 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003706
3707 DI = getDerived().TransformType(DI);
3708 if (!DI) return true;
3709
3710 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3711 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003712 }
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003714 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003715 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3716 if (QualifierLoc) {
3717 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3718 if (!QualifierLoc)
3719 return true;
3720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
Douglas Gregordf846d12011-03-02 18:46:51 +00003722 CXXScopeSpec SS;
3723 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003724 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003725 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3726 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003727 if (Template.isNull())
3728 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003729
Douglas Gregor9d802122011-03-02 17:09:35 +00003730 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003731 Input.getTemplateNameLoc());
3732 return false;
3733 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003734
3735 case TemplateArgument::TemplateExpansion:
3736 llvm_unreachable("Caller should expand pack expansions");
3737
Douglas Gregore922c772009-08-04 22:27:00 +00003738 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003739 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003740 EnterExpressionEvaluationContext Unevaluated(
3741 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003742
John McCall0ad16662009-10-29 08:12:44 +00003743 Expr *InputExpr = Input.getSourceExpression();
3744 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3745
Chris Lattnercdb591a2011-04-25 20:37:58 +00003746 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003747 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003748 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003749 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003750 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003751 }
Douglas Gregore922c772009-08-04 22:27:00 +00003752 }
Mike Stump11289f42009-09-09 15:08:12 +00003753
Douglas Gregore922c772009-08-04 22:27:00 +00003754 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003755 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003756}
3757
Douglas Gregorfe921a72010-12-20 23:36:19 +00003758/// \brief Iterator adaptor that invents template argument location information
3759/// for each of the template arguments in its underlying iterator.
3760template<typename Derived, typename InputIterator>
3761class TemplateArgumentLocInventIterator {
3762 TreeTransform<Derived> &Self;
3763 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregorfe921a72010-12-20 23:36:19 +00003765public:
3766 typedef TemplateArgumentLoc value_type;
3767 typedef TemplateArgumentLoc reference;
3768 typedef typename std::iterator_traits<InputIterator>::difference_type
3769 difference_type;
3770 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003771
Douglas Gregorfe921a72010-12-20 23:36:19 +00003772 class pointer {
3773 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregorfe921a72010-12-20 23:36:19 +00003775 public:
3776 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003777
Douglas Gregorfe921a72010-12-20 23:36:19 +00003778 const TemplateArgumentLoc *operator->() const { return &Arg; }
3779 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003780
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003781 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregorfe921a72010-12-20 23:36:19 +00003783 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3784 InputIterator Iter)
3785 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Douglas Gregorfe921a72010-12-20 23:36:19 +00003787 TemplateArgumentLocInventIterator &operator++() {
3788 ++Iter;
3789 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregorfe921a72010-12-20 23:36:19 +00003792 TemplateArgumentLocInventIterator operator++(int) {
3793 TemplateArgumentLocInventIterator Old(*this);
3794 ++(*this);
3795 return Old;
3796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
Douglas Gregorfe921a72010-12-20 23:36:19 +00003798 reference operator*() const {
3799 TemplateArgumentLoc Result;
3800 Self.InventTemplateArgumentLoc(*Iter, Result);
3801 return Result;
3802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003803
Douglas Gregorfe921a72010-12-20 23:36:19 +00003804 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003805
Douglas Gregorfe921a72010-12-20 23:36:19 +00003806 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3807 const TemplateArgumentLocInventIterator &Y) {
3808 return X.Iter == Y.Iter;
3809 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003810
Douglas Gregorfe921a72010-12-20 23:36:19 +00003811 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3812 const TemplateArgumentLocInventIterator &Y) {
3813 return X.Iter != Y.Iter;
3814 }
3815};
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregor42cafa82010-12-20 17:42:22 +00003817template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003818template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003819bool TreeTransform<Derived>::TransformTemplateArguments(
3820 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3821 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003822 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003823 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003824 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003826 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3827 // Unpack argument packs, which we translate them into separate
3828 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003829 // FIXME: We could do much better if we could guarantee that the
3830 // TemplateArgumentLocInfo for the pack expansion would be usable for
3831 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003832 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003833 TemplateArgument::pack_iterator>
3834 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003835 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003836 In.getArgument().pack_begin()),
3837 PackLocIterator(*this,
3838 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003839 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003840 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003842 continue;
3843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003845 if (In.getArgument().isPackExpansion()) {
3846 // We have a pack expansion, for which we will be substituting into
3847 // the pattern.
3848 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003849 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003850 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003851 = getSema().getTemplateArgumentPackExpansionPattern(
3852 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
Chris Lattner01cf8db2011-07-20 06:58:45 +00003854 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003855 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3856 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003857
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003858 // Determine whether the set of unexpanded parameter packs can and should
3859 // be expanded.
3860 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003861 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003862 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003863 if (getDerived().TryExpandParameterPacks(Ellipsis,
3864 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003865 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003867 RetainExpansion,
3868 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003869 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003871 if (!Expand) {
3872 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003873 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003874 // expansion.
3875 TemplateArgumentLoc OutPattern;
3876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003877 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003878 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003880 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3881 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003882 if (Out.getArgument().isNull())
3883 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003885 Outputs.addArgument(Out);
3886 continue;
3887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003889 // The transform has determined that we should perform an elementwise
3890 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003891 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003892 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3893
Richard Smithd784e682015-09-23 21:41:42 +00003894 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003895 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003897 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003898 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3899 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003900 if (Out.getArgument().isNull())
3901 return true;
3902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003904 Outputs.addArgument(Out);
3905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003906
Douglas Gregor48d24112011-01-10 20:53:55 +00003907 // If we're supposed to retain a pack expansion, do so by temporarily
3908 // forgetting the partially-substituted parameter pack.
3909 if (RetainExpansion) {
3910 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
Richard Smithd784e682015-09-23 21:41:42 +00003912 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003913 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003915 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3916 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003917 if (Out.getArgument().isNull())
3918 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003919
Douglas Gregor48d24112011-01-10 20:53:55 +00003920 Outputs.addArgument(Out);
3921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003922
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003923 continue;
3924 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003925
3926 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003927 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003928 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregor42cafa82010-12-20 17:42:22 +00003930 Outputs.addArgument(Out);
3931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003932
Douglas Gregor42cafa82010-12-20 17:42:22 +00003933 return false;
3934
3935}
3936
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937//===----------------------------------------------------------------------===//
3938// Type transformation
3939//===----------------------------------------------------------------------===//
3940
3941template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003942QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003943 if (getDerived().AlreadyTransformed(T))
3944 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003945
John McCall550e0c22009-10-21 00:40:46 +00003946 // Temporary workaround. All of these transformations should
3947 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003948 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3949 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003950
John McCall31f82722010-11-12 08:19:04 +00003951 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003952
John McCall550e0c22009-10-21 00:40:46 +00003953 if (!NewDI)
3954 return QualType();
3955
3956 return NewDI->getType();
3957}
3958
3959template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003960TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003961 // Refine the base location to the type's location.
3962 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3963 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003964 if (getDerived().AlreadyTransformed(DI->getType()))
3965 return DI;
3966
3967 TypeLocBuilder TLB;
3968
3969 TypeLoc TL = DI->getTypeLoc();
3970 TLB.reserve(TL.getFullDataSize());
3971
John McCall31f82722010-11-12 08:19:04 +00003972 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003973 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003974 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003975
John McCallbcd03502009-12-07 02:54:59 +00003976 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003977}
3978
3979template<typename Derived>
3980QualType
John McCall31f82722010-11-12 08:19:04 +00003981TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003982 switch (T.getTypeLocClass()) {
3983#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003984#define TYPELOC(CLASS, PARENT) \
3985 case TypeLoc::CLASS: \
3986 return getDerived().Transform##CLASS##Type(TLB, \
3987 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003988#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 }
Mike Stump11289f42009-09-09 15:08:12 +00003990
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003991 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003992}
3993
3994/// FIXME: By default, this routine adds type qualifiers only to types
3995/// that can have qualifiers, and silently suppresses those qualifiers
3996/// that are not permitted (e.g., qualifiers on reference or function
3997/// types). This is the right thing for template instantiation, but
3998/// probably not for other clients.
3999template<typename Derived>
4000QualType
4001TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004002 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004003 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004004
John McCall31f82722010-11-12 08:19:04 +00004005 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004006 if (Result.isNull())
4007 return QualType();
4008
4009 // Silently suppress qualifiers if the result type can't be qualified.
4010 // FIXME: this is the right thing for template instantiation, but
4011 // probably not for other clients.
4012 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004014
John McCall31168b02011-06-15 23:02:42 +00004015 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004016 // resulting type.
4017 if (Quals.hasObjCLifetime()) {
4018 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4019 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004020 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004021 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004022 // A lifetime qualifier applied to a substituted template parameter
4023 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004024 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004025 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004026 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4027 QualType Replacement = SubstTypeParam->getReplacementType();
4028 Qualifiers Qs = Replacement.getQualifiers();
4029 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004030 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004031 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4032 Qs);
4033 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004034 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004035 Replacement);
4036 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004037 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4038 // 'auto' types behave the same way as template parameters.
4039 QualType Deduced = AutoTy->getDeducedType();
4040 Qualifiers Qs = Deduced.getQualifiers();
4041 Qs.removeObjCLifetime();
4042 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4043 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004044 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004045 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004046 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004047 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004048 // Otherwise, complain about the addition of a qualifier to an
4049 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004050 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004051 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004052 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004053
Douglas Gregore46db902011-06-17 22:11:49 +00004054 Quals.removeObjCLifetime();
4055 }
4056 }
4057 }
John McCallcb0f89a2010-06-05 06:41:15 +00004058 if (!Quals.empty()) {
4059 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004060 // BuildQualifiedType might not add qualifiers if they are invalid.
4061 if (Result.hasLocalQualifiers())
4062 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004063 // No location information to preserve.
4064 }
John McCall550e0c22009-10-21 00:40:46 +00004065
4066 return Result;
4067}
4068
Douglas Gregor14454802011-02-25 02:25:35 +00004069template<typename Derived>
4070TypeLoc
4071TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4072 QualType ObjectType,
4073 NamedDecl *UnqualLookup,
4074 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004075 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004076 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004077
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004078 TypeSourceInfo *TSI =
4079 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4080 if (TSI)
4081 return TSI->getTypeLoc();
4082 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004083}
4084
Douglas Gregor579c15f2011-03-02 18:32:08 +00004085template<typename Derived>
4086TypeSourceInfo *
4087TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4088 QualType ObjectType,
4089 NamedDecl *UnqualLookup,
4090 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004091 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004092 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004093
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004094 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4095 UnqualLookup, SS);
4096}
4097
4098template <typename Derived>
4099TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4100 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4101 CXXScopeSpec &SS) {
4102 QualType T = TL.getType();
4103 assert(!getDerived().AlreadyTransformed(T));
4104
Douglas Gregor579c15f2011-03-02 18:32:08 +00004105 TypeLocBuilder TLB;
4106 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004107
Douglas Gregor579c15f2011-03-02 18:32:08 +00004108 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004109 TemplateSpecializationTypeLoc SpecTL =
4110 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
Douglas Gregor579c15f2011-03-02 18:32:08 +00004112 TemplateName Template
4113 = getDerived().TransformTemplateName(SS,
4114 SpecTL.getTypePtr()->getTemplateName(),
4115 SpecTL.getTemplateNameLoc(),
4116 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004117 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004118 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004119
4120 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004121 Template);
4122 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004123 DependentTemplateSpecializationTypeLoc SpecTL =
4124 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004125
Douglas Gregor579c15f2011-03-02 18:32:08 +00004126 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004127 = getDerived().RebuildTemplateName(SS,
4128 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004129 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004130 ObjectType, UnqualLookup);
4131 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004132 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004133
4134 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004135 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004136 Template,
4137 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004138 } else {
4139 // Nothing special needs to be done for these.
4140 Result = getDerived().TransformType(TLB, TL);
4141 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
4143 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004144 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004145
Douglas Gregor579c15f2011-03-02 18:32:08 +00004146 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4147}
4148
John McCall550e0c22009-10-21 00:40:46 +00004149template <class TyLoc> static inline
4150QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4151 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4152 NewT.setNameLoc(T.getNameLoc());
4153 return T.getType();
4154}
4155
John McCall550e0c22009-10-21 00:40:46 +00004156template<typename Derived>
4157QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004158 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004159 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4160 NewT.setBuiltinLoc(T.getBuiltinLoc());
4161 if (T.needsExtraLocalData())
4162 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4163 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164}
Mike Stump11289f42009-09-09 15:08:12 +00004165
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004167QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004168 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004169 // FIXME: recurse?
4170 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
Reid Kleckner0503a872013-12-05 01:23:43 +00004173template <typename Derived>
4174QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4175 AdjustedTypeLoc TL) {
4176 // Adjustments applied during transformation are handled elsewhere.
4177 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4178}
4179
Douglas Gregord6ff3322009-08-04 16:50:30 +00004180template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004181QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4182 DecayedTypeLoc TL) {
4183 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4184 if (OriginalType.isNull())
4185 return QualType();
4186
4187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() ||
4189 OriginalType != TL.getOriginalLoc().getType())
4190 Result = SemaRef.Context.getDecayedType(OriginalType);
4191 TLB.push<DecayedTypeLoc>(Result);
4192 // Nothing to set for DecayedTypeLoc.
4193 return Result;
4194}
4195
4196template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004197QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004198 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004199 QualType PointeeType
4200 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004201 if (PointeeType.isNull())
4202 return QualType();
4203
4204 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004205 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004206 // A dependent pointer type 'T *' has is being transformed such
4207 // that an Objective-C class type is being replaced for 'T'. The
4208 // resulting pointer type is an ObjCObjectPointerType, not a
4209 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004210 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
John McCall8b07ec22010-05-15 11:32:37 +00004212 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4213 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004214 return Result;
4215 }
John McCall31f82722010-11-12 08:19:04 +00004216
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004217 if (getDerived().AlwaysRebuild() ||
4218 PointeeType != TL.getPointeeLoc().getType()) {
4219 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4220 if (Result.isNull())
4221 return QualType();
4222 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004223
John McCall31168b02011-06-15 23:02:42 +00004224 // Objective-C ARC can add lifetime qualifiers to the type that we're
4225 // pointing to.
4226 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004227
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004228 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4229 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
4233template<typename Derived>
4234QualType
John McCall550e0c22009-10-21 00:40:46 +00004235TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004236 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004237 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004238 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4239 if (PointeeType.isNull())
4240 return QualType();
4241
4242 QualType Result = TL.getType();
4243 if (getDerived().AlwaysRebuild() ||
4244 PointeeType != TL.getPointeeLoc().getType()) {
4245 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004246 TL.getSigilLoc());
4247 if (Result.isNull())
4248 return QualType();
4249 }
4250
Douglas Gregor049211a2010-04-22 16:50:51 +00004251 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004252 NewT.setSigilLoc(TL.getSigilLoc());
4253 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254}
4255
John McCall70dd5f62009-10-30 00:06:24 +00004256/// Transforms a reference type. Note that somewhat paradoxically we
4257/// don't care whether the type itself is an l-value type or an r-value
4258/// type; we only care if the type was *written* as an l-value type
4259/// or an r-value type.
4260template<typename Derived>
4261QualType
4262TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004263 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004264 const ReferenceType *T = TL.getTypePtr();
4265
4266 // Note that this works with the pointee-as-written.
4267 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4268 if (PointeeType.isNull())
4269 return QualType();
4270
4271 QualType Result = TL.getType();
4272 if (getDerived().AlwaysRebuild() ||
4273 PointeeType != T->getPointeeTypeAsWritten()) {
4274 Result = getDerived().RebuildReferenceType(PointeeType,
4275 T->isSpelledAsLValue(),
4276 TL.getSigilLoc());
4277 if (Result.isNull())
4278 return QualType();
4279 }
4280
John McCall31168b02011-06-15 23:02:42 +00004281 // Objective-C ARC can add lifetime qualifiers to the type that we're
4282 // referring to.
4283 TLB.TypeWasModifiedSafely(
4284 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4285
John McCall70dd5f62009-10-30 00:06:24 +00004286 // r-value references can be rebuilt as l-value references.
4287 ReferenceTypeLoc NewTL;
4288 if (isa<LValueReferenceType>(Result))
4289 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4290 else
4291 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4292 NewTL.setSigilLoc(TL.getSigilLoc());
4293
4294 return Result;
4295}
4296
Mike Stump11289f42009-09-09 15:08:12 +00004297template<typename Derived>
4298QualType
John McCall550e0c22009-10-21 00:40:46 +00004299TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004300 LValueReferenceTypeLoc TL) {
4301 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004302}
4303
Mike Stump11289f42009-09-09 15:08:12 +00004304template<typename Derived>
4305QualType
John McCall550e0c22009-10-21 00:40:46 +00004306TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004307 RValueReferenceTypeLoc TL) {
4308 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregord6ff3322009-08-04 16:50:30 +00004311template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004312QualType
John McCall550e0c22009-10-21 00:40:46 +00004313TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004314 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004315 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004316 if (PointeeType.isNull())
4317 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004318
Abramo Bagnara509357842011-03-05 14:42:21 +00004319 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004320 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004321 if (OldClsTInfo) {
4322 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4323 if (!NewClsTInfo)
4324 return QualType();
4325 }
4326
4327 const MemberPointerType *T = TL.getTypePtr();
4328 QualType OldClsType = QualType(T->getClass(), 0);
4329 QualType NewClsType;
4330 if (NewClsTInfo)
4331 NewClsType = NewClsTInfo->getType();
4332 else {
4333 NewClsType = getDerived().TransformType(OldClsType);
4334 if (NewClsType.isNull())
4335 return QualType();
4336 }
Mike Stump11289f42009-09-09 15:08:12 +00004337
John McCall550e0c22009-10-21 00:40:46 +00004338 QualType Result = TL.getType();
4339 if (getDerived().AlwaysRebuild() ||
4340 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004341 NewClsType != OldClsType) {
4342 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004343 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004344 if (Result.isNull())
4345 return QualType();
4346 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347
Reid Kleckner0503a872013-12-05 01:23:43 +00004348 // If we had to adjust the pointee type when building a member pointer, make
4349 // sure to push TypeLoc info for it.
4350 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4351 if (MPT && PointeeType != MPT->getPointeeType()) {
4352 assert(isa<AdjustedType>(MPT->getPointeeType()));
4353 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4354 }
4355
John McCall550e0c22009-10-21 00:40:46 +00004356 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4357 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004358 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004359
4360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004361}
4362
Mike Stump11289f42009-09-09 15:08:12 +00004363template<typename Derived>
4364QualType
John McCall550e0c22009-10-21 00:40:46 +00004365TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004366 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004367 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004368 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004369 if (ElementType.isNull())
4370 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall550e0c22009-10-21 00:40:46 +00004372 QualType Result = TL.getType();
4373 if (getDerived().AlwaysRebuild() ||
4374 ElementType != T->getElementType()) {
4375 Result = getDerived().RebuildConstantArrayType(ElementType,
4376 T->getSizeModifier(),
4377 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004378 T->getIndexTypeCVRQualifiers(),
4379 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004380 if (Result.isNull())
4381 return QualType();
4382 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004383
4384 // We might have either a ConstantArrayType or a VariableArrayType now:
4385 // a ConstantArrayType is allowed to have an element type which is a
4386 // VariableArrayType if the type is dependent. Fortunately, all array
4387 // types have the same location layout.
4388 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004389 NewTL.setLBracketLoc(TL.getLBracketLoc());
4390 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004391
John McCall550e0c22009-10-21 00:40:46 +00004392 Expr *Size = TL.getSizeExpr();
4393 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004394 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4395 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004396 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4397 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004398 }
4399 NewTL.setSizeExpr(Size);
4400
4401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402}
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregord6ff3322009-08-04 16:50:30 +00004404template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004405QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004406 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004407 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004408 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004409 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004410 if (ElementType.isNull())
4411 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004412
John McCall550e0c22009-10-21 00:40:46 +00004413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
4415 ElementType != T->getElementType()) {
4416 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004418 T->getIndexTypeCVRQualifiers(),
4419 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004420 if (Result.isNull())
4421 return QualType();
4422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004423
John McCall550e0c22009-10-21 00:40:46 +00004424 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4425 NewTL.setLBracketLoc(TL.getLBracketLoc());
4426 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004427 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004428
4429 return Result;
4430}
4431
4432template<typename Derived>
4433QualType
4434TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004435 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004436 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004437 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4438 if (ElementType.isNull())
4439 return QualType();
4440
John McCalldadc5752010-08-24 06:29:42 +00004441 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004442 = getDerived().TransformExpr(T->getSizeExpr());
4443 if (SizeResult.isInvalid())
4444 return QualType();
4445
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004446 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004447
4448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() ||
4450 ElementType != T->getElementType() ||
4451 Size != T->getSizeExpr()) {
4452 Result = getDerived().RebuildVariableArrayType(ElementType,
4453 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004454 Size,
John McCall550e0c22009-10-21 00:40:46 +00004455 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004456 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004457 if (Result.isNull())
4458 return QualType();
4459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
Serge Pavlov774c6d02014-02-06 03:49:11 +00004461 // We might have constant size array now, but fortunately it has the same
4462 // location layout.
4463 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004464 NewTL.setLBracketLoc(TL.getLBracketLoc());
4465 NewTL.setRBracketLoc(TL.getRBracketLoc());
4466 NewTL.setSizeExpr(Size);
4467
4468 return Result;
4469}
4470
4471template<typename Derived>
4472QualType
4473TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004474 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004475 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004476 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4477 if (ElementType.isNull())
4478 return QualType();
4479
Richard Smith764d2fe2011-12-20 02:08:33 +00004480 // Array bounds are constant expressions.
4481 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4482 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004483
John McCall33ddac02011-01-19 10:06:00 +00004484 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4485 Expr *origSize = TL.getSizeExpr();
4486 if (!origSize) origSize = T->getSizeExpr();
4487
4488 ExprResult sizeResult
4489 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004490 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004491 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004492 return QualType();
4493
John McCall33ddac02011-01-19 10:06:00 +00004494 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004495
4496 QualType Result = TL.getType();
4497 if (getDerived().AlwaysRebuild() ||
4498 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004499 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004500 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4501 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004502 size,
John McCall550e0c22009-10-21 00:40:46 +00004503 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004504 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004505 if (Result.isNull())
4506 return QualType();
4507 }
John McCall550e0c22009-10-21 00:40:46 +00004508
4509 // We might have any sort of array type now, but fortunately they
4510 // all have the same location layout.
4511 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4512 NewTL.setLBracketLoc(TL.getLBracketLoc());
4513 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004514 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004515
4516 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517}
Mike Stump11289f42009-09-09 15:08:12 +00004518
4519template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004520QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004521 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004522 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004523 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004524
4525 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526 QualType ElementType = getDerived().TransformType(T->getElementType());
4527 if (ElementType.isNull())
4528 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Richard Smith764d2fe2011-12-20 02:08:33 +00004530 // Vector sizes are constant expressions.
4531 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4532 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004533
John McCalldadc5752010-08-24 06:29:42 +00004534 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004535 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 if (Size.isInvalid())
4537 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004538
John McCall550e0c22009-10-21 00:40:46 +00004539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004541 ElementType != T->getElementType() ||
4542 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004543 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004544 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004546 if (Result.isNull())
4547 return QualType();
4548 }
John McCall550e0c22009-10-21 00:40:46 +00004549
4550 // Result might be dependent or not.
4551 if (isa<DependentSizedExtVectorType>(Result)) {
4552 DependentSizedExtVectorTypeLoc NewTL
4553 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4554 NewTL.setNameLoc(TL.getNameLoc());
4555 } else {
4556 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4557 NewTL.setNameLoc(TL.getNameLoc());
4558 }
4559
4560 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
4563template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004564QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004565 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004566 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004567 QualType ElementType = getDerived().TransformType(T->getElementType());
4568 if (ElementType.isNull())
4569 return QualType();
4570
John McCall550e0c22009-10-21 00:40:46 +00004571 QualType Result = TL.getType();
4572 if (getDerived().AlwaysRebuild() ||
4573 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004574 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004575 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004576 if (Result.isNull())
4577 return QualType();
4578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004579
John McCall550e0c22009-10-21 00:40:46 +00004580 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4581 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004582
John McCall550e0c22009-10-21 00:40:46 +00004583 return Result;
4584}
4585
4586template<typename Derived>
4587QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004588 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004589 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004590 QualType ElementType = getDerived().TransformType(T->getElementType());
4591 if (ElementType.isNull())
4592 return QualType();
4593
4594 QualType Result = TL.getType();
4595 if (getDerived().AlwaysRebuild() ||
4596 ElementType != T->getElementType()) {
4597 Result = getDerived().RebuildExtVectorType(ElementType,
4598 T->getNumElements(),
4599 /*FIXME*/ SourceLocation());
4600 if (Result.isNull())
4601 return QualType();
4602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004603
John McCall550e0c22009-10-21 00:40:46 +00004604 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4605 NewTL.setNameLoc(TL.getNameLoc());
4606
4607 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004608}
Mike Stump11289f42009-09-09 15:08:12 +00004609
David Blaikie05785d12013-02-20 22:23:23 +00004610template <typename Derived>
4611ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4612 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4613 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004614 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004615 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004616
Douglas Gregor715e4612011-01-14 22:40:04 +00004617 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004618 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004619 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004620 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004621 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004622
Douglas Gregor715e4612011-01-14 22:40:04 +00004623 TypeLocBuilder TLB;
4624 TypeLoc NewTL = OldDI->getTypeLoc();
4625 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004626
4627 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004628 OldExpansionTL.getPatternLoc());
4629 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004630 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004631
4632 Result = RebuildPackExpansionType(Result,
4633 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004634 OldExpansionTL.getEllipsisLoc(),
4635 NumExpansions);
4636 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004637 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004638
Douglas Gregor715e4612011-01-14 22:40:04 +00004639 PackExpansionTypeLoc NewExpansionTL
4640 = TLB.push<PackExpansionTypeLoc>(Result);
4641 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4642 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4643 } else
4644 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004645 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004646 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004647
John McCall8fb0d9d2011-05-01 22:35:37 +00004648 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004649 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004650
4651 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4652 OldParm->getDeclContext(),
4653 OldParm->getInnerLocStart(),
4654 OldParm->getLocation(),
4655 OldParm->getIdentifier(),
4656 NewDI->getType(),
4657 NewDI,
4658 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004659 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004660 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4661 OldParm->getFunctionScopeIndex() + indexAdjustment);
4662 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004663}
4664
David Majnemer59f77922016-06-24 04:05:48 +00004665template <typename Derived>
4666bool TreeTransform<Derived>::TransformFunctionTypeParams(
4667 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4668 const QualType *ParamTypes,
4669 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4670 SmallVectorImpl<QualType> &OutParamTypes,
4671 SmallVectorImpl<ParmVarDecl *> *PVars,
4672 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004673 int indexAdjustment = 0;
4674
David Majnemer59f77922016-06-24 04:05:48 +00004675 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004676 for (unsigned i = 0; i != NumParams; ++i) {
4677 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004678 assert(OldParm->getFunctionScopeIndex() == i);
4679
David Blaikie05785d12013-02-20 22:23:23 +00004680 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004681 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004682 if (OldParm->isParameterPack()) {
4683 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004684 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004685
Douglas Gregor5499af42011-01-05 23:12:31 +00004686 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004687 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004688 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004689 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4690 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004691 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4692
Douglas Gregor5499af42011-01-05 23:12:31 +00004693 // Determine whether we should expand the parameter packs.
4694 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004695 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004696 Optional<unsigned> OrigNumExpansions =
4697 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004698 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004699 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4700 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004701 Unexpanded,
4702 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004703 RetainExpansion,
4704 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004705 return true;
4706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004707
Douglas Gregor5499af42011-01-05 23:12:31 +00004708 if (ShouldExpand) {
4709 // Expand the function parameter pack into multiple, separate
4710 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004711 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004712 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004713 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004714 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004715 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004716 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004717 OrigNumExpansions,
4718 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004719 if (!NewParm)
4720 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004721
John McCallc8e321d2016-03-01 02:09:25 +00004722 if (ParamInfos)
4723 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004724 OutParamTypes.push_back(NewParm->getType());
4725 if (PVars)
4726 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004727 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004728
4729 // If we're supposed to retain a pack expansion, do so by temporarily
4730 // forgetting the partially-substituted parameter pack.
4731 if (RetainExpansion) {
4732 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004733 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004734 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004735 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004736 OrigNumExpansions,
4737 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004738 if (!NewParm)
4739 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004740
John McCallc8e321d2016-03-01 02:09:25 +00004741 if (ParamInfos)
4742 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004743 OutParamTypes.push_back(NewParm->getType());
4744 if (PVars)
4745 PVars->push_back(NewParm);
4746 }
4747
John McCall8fb0d9d2011-05-01 22:35:37 +00004748 // The next parameter should have the same adjustment as the
4749 // last thing we pushed, but we post-incremented indexAdjustment
4750 // on every push. Also, if we push nothing, the adjustment should
4751 // go down by one.
4752 indexAdjustment--;
4753
Douglas Gregor5499af42011-01-05 23:12:31 +00004754 // We're done with the pack expansion.
4755 continue;
4756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004757
4758 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004759 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004760 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4761 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004762 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004763 NumExpansions,
4764 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004765 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004766 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004767 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004768 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004769
John McCall58f10c32010-03-11 09:03:00 +00004770 if (!NewParm)
4771 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004772
John McCallc8e321d2016-03-01 02:09:25 +00004773 if (ParamInfos)
4774 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004775 OutParamTypes.push_back(NewParm->getType());
4776 if (PVars)
4777 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004778 continue;
4779 }
John McCall58f10c32010-03-11 09:03:00 +00004780
4781 // Deal with the possibility that we don't have a parameter
4782 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004783 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004784 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004785 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004786 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004787 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004788 = dyn_cast<PackExpansionType>(OldType)) {
4789 // We have a function parameter pack that may need to be expanded.
4790 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004791 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004792 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004793
Douglas Gregor5499af42011-01-05 23:12:31 +00004794 // Determine whether we should expand the parameter packs.
4795 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004796 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004797 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004798 Unexpanded,
4799 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004800 RetainExpansion,
4801 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004802 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
Douglas Gregor5499af42011-01-05 23:12:31 +00004805 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004806 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004807 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004808 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004809 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4810 QualType NewType = getDerived().TransformType(Pattern);
4811 if (NewType.isNull())
4812 return true;
John McCall58f10c32010-03-11 09:03:00 +00004813
John McCallc8e321d2016-03-01 02:09:25 +00004814 if (ParamInfos)
4815 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004816 OutParamTypes.push_back(NewType);
4817 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004818 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004820
Douglas Gregor5499af42011-01-05 23:12:31 +00004821 // We're done with the pack expansion.
4822 continue;
4823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004824
Douglas Gregor48d24112011-01-10 20:53:55 +00004825 // If we're supposed to retain a pack expansion, do so by temporarily
4826 // forgetting the partially-substituted parameter pack.
4827 if (RetainExpansion) {
4828 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4829 QualType NewType = getDerived().TransformType(Pattern);
4830 if (NewType.isNull())
4831 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004832
John McCallc8e321d2016-03-01 02:09:25 +00004833 if (ParamInfos)
4834 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004835 OutParamTypes.push_back(NewType);
4836 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004837 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004838 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004839
Chad Rosier1dcde962012-08-08 18:46:20 +00004840 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004841 // expansion.
4842 OldType = Expansion->getPattern();
4843 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4845 NewType = getDerived().TransformType(OldType);
4846 } else {
4847 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
Douglas Gregor5499af42011-01-05 23:12:31 +00004850 if (NewType.isNull())
4851 return true;
4852
4853 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004854 NewType = getSema().Context.getPackExpansionType(NewType,
4855 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
John McCallc8e321d2016-03-01 02:09:25 +00004857 if (ParamInfos)
4858 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004859 OutParamTypes.push_back(NewType);
4860 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004861 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004862 }
4863
John McCall8fb0d9d2011-05-01 22:35:37 +00004864#ifndef NDEBUG
4865 if (PVars) {
4866 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4867 if (ParmVarDecl *parm = (*PVars)[i])
4868 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004869 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004870#endif
4871
4872 return false;
4873}
John McCall58f10c32010-03-11 09:03:00 +00004874
4875template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004876QualType
John McCall550e0c22009-10-21 00:40:46 +00004877TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004878 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004879 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004880 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004881 return getDerived().TransformFunctionProtoType(
4882 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004883 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4884 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4885 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004886 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004887}
4888
Richard Smith2e321552014-11-12 02:00:47 +00004889template<typename Derived> template<typename Fn>
4890QualType TreeTransform<Derived>::TransformFunctionProtoType(
4891 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4892 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004893
Douglas Gregor4afc2362010-08-31 00:26:14 +00004894 // Transform the parameters and return type.
4895 //
Richard Smithf623c962012-04-17 00:58:00 +00004896 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004897 // When the function has a trailing return type, we instantiate the
4898 // parameters before the return type, since the return type can then refer
4899 // to the parameters themselves (via decltype, sizeof, etc.).
4900 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004901 SmallVector<QualType, 4> ParamTypes;
4902 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004903 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004904 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004905
Douglas Gregor7fb25412010-10-01 18:44:50 +00004906 QualType ResultType;
4907
Richard Smith1226c602012-08-14 22:51:13 +00004908 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004909 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004910 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004911 TL.getTypePtr()->param_type_begin(),
4912 T->getExtParameterInfosOrNull(),
4913 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004914 return QualType();
4915
Douglas Gregor3024f072012-04-16 07:05:22 +00004916 {
4917 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004918 // If a declaration declares a member function or member function
4919 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004920 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004921 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004922 // declarator.
4923 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004924
Alp Toker42a16a62014-01-25 23:51:36 +00004925 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004926 if (ResultType.isNull())
4927 return QualType();
4928 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004929 }
4930 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004931 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004932 if (ResultType.isNull())
4933 return QualType();
4934
Alp Toker9cacbab2014-01-20 20:26:09 +00004935 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004936 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004937 TL.getTypePtr()->param_type_begin(),
4938 T->getExtParameterInfosOrNull(),
4939 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004940 return QualType();
4941 }
4942
Richard Smith2e321552014-11-12 02:00:47 +00004943 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4944
4945 bool EPIChanged = false;
4946 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4947 return QualType();
4948
John McCallc8e321d2016-03-01 02:09:25 +00004949 // Handle extended parameter information.
4950 if (auto NewExtParamInfos =
4951 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4952 if (!EPI.ExtParameterInfos ||
4953 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4954 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4955 EPIChanged = true;
4956 }
4957 EPI.ExtParameterInfos = NewExtParamInfos;
4958 } else if (EPI.ExtParameterInfos) {
4959 EPIChanged = true;
4960 EPI.ExtParameterInfos = nullptr;
4961 }
Richard Smithf623c962012-04-17 00:58:00 +00004962
John McCall550e0c22009-10-21 00:40:46 +00004963 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004964 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004965 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004966 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004967 if (Result.isNull())
4968 return QualType();
4969 }
Mike Stump11289f42009-09-09 15:08:12 +00004970
John McCall550e0c22009-10-21 00:40:46 +00004971 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004972 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004973 NewTL.setLParenLoc(TL.getLParenLoc());
4974 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004975 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004976 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4977 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004978
4979 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980}
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregord6ff3322009-08-04 16:50:30 +00004982template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004983bool TreeTransform<Derived>::TransformExceptionSpec(
4984 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4985 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4986 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4987
4988 // Instantiate a dynamic noexcept expression, if any.
4989 if (ESI.Type == EST_ComputedNoexcept) {
4990 EnterExpressionEvaluationContext Unevaluated(getSema(),
4991 Sema::ConstantEvaluated);
4992 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4993 if (NoexceptExpr.isInvalid())
4994 return true;
4995
Richard Smith03a4aa32016-06-23 19:02:52 +00004996 // FIXME: This is bogus, a noexcept expression is not a condition.
4997 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00004998 if (NoexceptExpr.isInvalid())
4999 return true;
5000
5001 if (!NoexceptExpr.get()->isValueDependent()) {
5002 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5003 NoexceptExpr.get(), nullptr,
5004 diag::err_noexcept_needs_constant_expression,
5005 /*AllowFold*/false);
5006 if (NoexceptExpr.isInvalid())
5007 return true;
5008 }
5009
5010 if (ESI.NoexceptExpr != NoexceptExpr.get())
5011 Changed = true;
5012 ESI.NoexceptExpr = NoexceptExpr.get();
5013 }
5014
5015 if (ESI.Type != EST_Dynamic)
5016 return false;
5017
5018 // Instantiate a dynamic exception specification's type.
5019 for (QualType T : ESI.Exceptions) {
5020 if (const PackExpansionType *PackExpansion =
5021 T->getAs<PackExpansionType>()) {
5022 Changed = true;
5023
5024 // We have a pack expansion. Instantiate it.
5025 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5026 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5027 Unexpanded);
5028 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5029
5030 // Determine whether the set of unexpanded parameter packs can and
5031 // should
5032 // be expanded.
5033 bool Expand = false;
5034 bool RetainExpansion = false;
5035 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5036 // FIXME: Track the location of the ellipsis (and track source location
5037 // information for the types in the exception specification in general).
5038 if (getDerived().TryExpandParameterPacks(
5039 Loc, SourceRange(), Unexpanded, Expand,
5040 RetainExpansion, NumExpansions))
5041 return true;
5042
5043 if (!Expand) {
5044 // We can't expand this pack expansion into separate arguments yet;
5045 // just substitute into the pattern and create a new pack expansion
5046 // type.
5047 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5048 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5049 if (U.isNull())
5050 return true;
5051
5052 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5053 Exceptions.push_back(U);
5054 continue;
5055 }
5056
5057 // Substitute into the pack expansion pattern for each slice of the
5058 // pack.
5059 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5061
5062 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5063 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5064 return true;
5065
5066 Exceptions.push_back(U);
5067 }
5068 } else {
5069 QualType U = getDerived().TransformType(T);
5070 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5071 return true;
5072 if (T != U)
5073 Changed = true;
5074
5075 Exceptions.push_back(U);
5076 }
5077 }
5078
5079 ESI.Exceptions = Exceptions;
5080 return false;
5081}
5082
5083template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005085 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005086 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005087 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005088 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005089 if (ResultType.isNull())
5090 return QualType();
5091
5092 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005093 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005094 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5095
5096 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005097 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005098 NewTL.setLParenLoc(TL.getLParenLoc());
5099 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005100 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005101
5102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
John McCallb96ec562009-12-04 22:46:56 +00005105template<typename Derived> QualType
5106TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005107 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005108 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005109 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005110 if (!D)
5111 return QualType();
5112
5113 QualType Result = TL.getType();
5114 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5115 Result = getDerived().RebuildUnresolvedUsingType(D);
5116 if (Result.isNull())
5117 return QualType();
5118 }
5119
5120 // We might get an arbitrary type spec type back. We should at
5121 // least always get a type spec type, though.
5122 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5123 NewTL.setNameLoc(TL.getNameLoc());
5124
5125 return Result;
5126}
5127
Douglas Gregord6ff3322009-08-04 16:50:30 +00005128template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005129QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005130 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005131 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005132 TypedefNameDecl *Typedef
5133 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5134 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005135 if (!Typedef)
5136 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005137
John McCall550e0c22009-10-21 00:40:46 +00005138 QualType Result = TL.getType();
5139 if (getDerived().AlwaysRebuild() ||
5140 Typedef != T->getDecl()) {
5141 Result = getDerived().RebuildTypedefType(Typedef);
5142 if (Result.isNull())
5143 return QualType();
5144 }
Mike Stump11289f42009-09-09 15:08:12 +00005145
John McCall550e0c22009-10-21 00:40:46 +00005146 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5147 NewTL.setNameLoc(TL.getNameLoc());
5148
5149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005150}
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005153QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005154 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005155 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005156 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5157 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005158
John McCalldadc5752010-08-24 06:29:42 +00005159 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160 if (E.isInvalid())
5161 return QualType();
5162
Eli Friedmane4f22df2012-02-29 04:03:55 +00005163 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5164 if (E.isInvalid())
5165 return QualType();
5166
John McCall550e0c22009-10-21 00:40:46 +00005167 QualType Result = TL.getType();
5168 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005169 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005170 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005171 if (Result.isNull())
5172 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005174 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005175
John McCall550e0c22009-10-21 00:40:46 +00005176 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005177 NewTL.setTypeofLoc(TL.getTypeofLoc());
5178 NewTL.setLParenLoc(TL.getLParenLoc());
5179 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005180
5181 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005182}
Mike Stump11289f42009-09-09 15:08:12 +00005183
5184template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005185QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005186 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005187 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5188 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5189 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005191
John McCall550e0c22009-10-21 00:40:46 +00005192 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005193 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5194 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005195 if (Result.isNull())
5196 return QualType();
5197 }
Mike Stump11289f42009-09-09 15:08:12 +00005198
John McCall550e0c22009-10-21 00:40:46 +00005199 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005200 NewTL.setTypeofLoc(TL.getTypeofLoc());
5201 NewTL.setLParenLoc(TL.getLParenLoc());
5202 NewTL.setRParenLoc(TL.getRParenLoc());
5203 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005204
5205 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005206}
Mike Stump11289f42009-09-09 15:08:12 +00005207
5208template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005209QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005210 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005211 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005212
Douglas Gregore922c772009-08-04 22:27:00 +00005213 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005214 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5215 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005218 if (E.isInvalid())
5219 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005220
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005221 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005222 if (E.isInvalid())
5223 return QualType();
5224
John McCall550e0c22009-10-21 00:40:46 +00005225 QualType Result = TL.getType();
5226 if (getDerived().AlwaysRebuild() ||
5227 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005228 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005229 if (Result.isNull())
5230 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005232 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005233
John McCall550e0c22009-10-21 00:40:46 +00005234 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5235 NewTL.setNameLoc(TL.getNameLoc());
5236
5237 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238}
5239
5240template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005241QualType TreeTransform<Derived>::TransformUnaryTransformType(
5242 TypeLocBuilder &TLB,
5243 UnaryTransformTypeLoc TL) {
5244 QualType Result = TL.getType();
5245 if (Result->isDependentType()) {
5246 const UnaryTransformType *T = TL.getTypePtr();
5247 QualType NewBase =
5248 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5249 Result = getDerived().RebuildUnaryTransformType(NewBase,
5250 T->getUTTKind(),
5251 TL.getKWLoc());
5252 if (Result.isNull())
5253 return QualType();
5254 }
5255
5256 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5257 NewTL.setKWLoc(TL.getKWLoc());
5258 NewTL.setParensRange(TL.getParensRange());
5259 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5260 return Result;
5261}
5262
5263template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005264QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5265 AutoTypeLoc TL) {
5266 const AutoType *T = TL.getTypePtr();
5267 QualType OldDeduced = T->getDeducedType();
5268 QualType NewDeduced;
5269 if (!OldDeduced.isNull()) {
5270 NewDeduced = getDerived().TransformType(OldDeduced);
5271 if (NewDeduced.isNull())
5272 return QualType();
5273 }
5274
5275 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005276 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5277 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005278 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005279 if (Result.isNull())
5280 return QualType();
5281 }
5282
5283 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5284 NewTL.setNameLoc(TL.getNameLoc());
5285
5286 return Result;
5287}
5288
5289template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005290QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005291 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005292 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005293 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005294 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5295 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296 if (!Record)
5297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005298
John McCall550e0c22009-10-21 00:40:46 +00005299 QualType Result = TL.getType();
5300 if (getDerived().AlwaysRebuild() ||
5301 Record != T->getDecl()) {
5302 Result = getDerived().RebuildRecordType(Record);
5303 if (Result.isNull())
5304 return QualType();
5305 }
Mike Stump11289f42009-09-09 15:08:12 +00005306
John McCall550e0c22009-10-21 00:40:46 +00005307 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5308 NewTL.setNameLoc(TL.getNameLoc());
5309
5310 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005311}
Mike Stump11289f42009-09-09 15:08:12 +00005312
5313template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005314QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005315 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005316 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005318 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5319 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320 if (!Enum)
5321 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005322
John McCall550e0c22009-10-21 00:40:46 +00005323 QualType Result = TL.getType();
5324 if (getDerived().AlwaysRebuild() ||
5325 Enum != T->getDecl()) {
5326 Result = getDerived().RebuildEnumType(Enum);
5327 if (Result.isNull())
5328 return QualType();
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
John McCall550e0c22009-10-21 00:40:46 +00005331 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5332 NewTL.setNameLoc(TL.getNameLoc());
5333
5334 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335}
John McCallfcc33b02009-09-05 00:15:47 +00005336
John McCalle78aac42010-03-10 03:28:59 +00005337template<typename Derived>
5338QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5339 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005340 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005341 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5342 TL.getTypePtr()->getDecl());
5343 if (!D) return QualType();
5344
5345 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5346 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5347 return T;
5348}
5349
Douglas Gregord6ff3322009-08-04 16:50:30 +00005350template<typename Derived>
5351QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005352 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005353 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005354 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005355}
5356
Mike Stump11289f42009-09-09 15:08:12 +00005357template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005358QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005359 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005360 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005361 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005362
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005363 // Substitute into the replacement type, which itself might involve something
5364 // that needs to be transformed. This only tends to occur with default
5365 // template arguments of template template parameters.
5366 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5367 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5368 if (Replacement.isNull())
5369 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005370
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005371 // Always canonicalize the replacement type.
5372 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5373 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005374 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005375 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005376
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005377 // Propagate type-source information.
5378 SubstTemplateTypeParmTypeLoc NewTL
5379 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5380 NewTL.setNameLoc(TL.getNameLoc());
5381 return Result;
5382
John McCallcebee162009-10-18 09:09:24 +00005383}
5384
5385template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005386QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5387 TypeLocBuilder &TLB,
5388 SubstTemplateTypeParmPackTypeLoc TL) {
5389 return TransformTypeSpecType(TLB, TL);
5390}
5391
5392template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005393QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005394 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005395 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005396 const TemplateSpecializationType *T = TL.getTypePtr();
5397
Douglas Gregordf846d12011-03-02 18:46:51 +00005398 // The nested-name-specifier never matters in a TemplateSpecializationType,
5399 // because we can't have a dependent nested-name-specifier anyway.
5400 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005401 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005402 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5403 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005404 if (Template.isNull())
5405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005406
John McCall31f82722010-11-12 08:19:04 +00005407 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5408}
5409
Eli Friedman0dfb8892011-10-06 23:00:33 +00005410template<typename Derived>
5411QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5412 AtomicTypeLoc TL) {
5413 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5414 if (ValueType.isNull())
5415 return QualType();
5416
5417 QualType Result = TL.getType();
5418 if (getDerived().AlwaysRebuild() ||
5419 ValueType != TL.getValueLoc().getType()) {
5420 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5421 if (Result.isNull())
5422 return QualType();
5423 }
5424
5425 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5426 NewTL.setKWLoc(TL.getKWLoc());
5427 NewTL.setLParenLoc(TL.getLParenLoc());
5428 NewTL.setRParenLoc(TL.getRParenLoc());
5429
5430 return Result;
5431}
5432
Xiuli Pan9c14e282016-01-09 12:53:17 +00005433template <typename Derived>
5434QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5435 PipeTypeLoc TL) {
5436 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5437 if (ValueType.isNull())
5438 return QualType();
5439
5440 QualType Result = TL.getType();
5441 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5442 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5443 if (Result.isNull())
5444 return QualType();
5445 }
5446
5447 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5448 NewTL.setKWLoc(TL.getKWLoc());
5449
5450 return Result;
5451}
5452
Chad Rosier1dcde962012-08-08 18:46:20 +00005453 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005454 /// container that provides a \c getArgLoc() member function.
5455 ///
5456 /// This iterator is intended to be used with the iterator form of
5457 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5458 template<typename ArgLocContainer>
5459 class TemplateArgumentLocContainerIterator {
5460 ArgLocContainer *Container;
5461 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005462
Douglas Gregorfe921a72010-12-20 23:36:19 +00005463 public:
5464 typedef TemplateArgumentLoc value_type;
5465 typedef TemplateArgumentLoc reference;
5466 typedef int difference_type;
5467 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005468
Douglas Gregorfe921a72010-12-20 23:36:19 +00005469 class pointer {
5470 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005471
Douglas Gregorfe921a72010-12-20 23:36:19 +00005472 public:
5473 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
Douglas Gregorfe921a72010-12-20 23:36:19 +00005475 const TemplateArgumentLoc *operator->() const {
5476 return &Arg;
5477 }
5478 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
5480
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005481 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005482
Douglas Gregorfe921a72010-12-20 23:36:19 +00005483 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5484 unsigned Index)
5485 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005486
Douglas Gregorfe921a72010-12-20 23:36:19 +00005487 TemplateArgumentLocContainerIterator &operator++() {
5488 ++Index;
5489 return *this;
5490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005491
Douglas Gregorfe921a72010-12-20 23:36:19 +00005492 TemplateArgumentLocContainerIterator operator++(int) {
5493 TemplateArgumentLocContainerIterator Old(*this);
5494 ++(*this);
5495 return Old;
5496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005497
Douglas Gregorfe921a72010-12-20 23:36:19 +00005498 TemplateArgumentLoc operator*() const {
5499 return Container->getArgLoc(Index);
5500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005501
Douglas Gregorfe921a72010-12-20 23:36:19 +00005502 pointer operator->() const {
5503 return pointer(Container->getArgLoc(Index));
5504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005505
Douglas Gregorfe921a72010-12-20 23:36:19 +00005506 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005507 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005508 return X.Container == Y.Container && X.Index == Y.Index;
5509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregorfe921a72010-12-20 23:36:19 +00005511 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005512 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005513 return !(X == Y);
5514 }
5515 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
5517
John McCall31f82722010-11-12 08:19:04 +00005518template <typename Derived>
5519QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5520 TypeLocBuilder &TLB,
5521 TemplateSpecializationTypeLoc TL,
5522 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005523 TemplateArgumentListInfo NewTemplateArgs;
5524 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5525 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005526 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5527 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005528 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005529 ArgIterator(TL, TL.getNumArgs()),
5530 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005531 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCall0ad16662009-10-29 08:12:44 +00005533 // FIXME: maybe don't rebuild if all the template arguments are the same.
5534
5535 QualType Result =
5536 getDerived().RebuildTemplateSpecializationType(Template,
5537 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005538 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005539
5540 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005541 // Specializations of template template parameters are represented as
5542 // TemplateSpecializationTypes, and substitution of type alias templates
5543 // within a dependent context can transform them into
5544 // DependentTemplateSpecializationTypes.
5545 if (isa<DependentTemplateSpecializationType>(Result)) {
5546 DependentTemplateSpecializationTypeLoc NewTL
5547 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005548 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005549 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005550 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005551 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005552 NewTL.setLAngleLoc(TL.getLAngleLoc());
5553 NewTL.setRAngleLoc(TL.getRAngleLoc());
5554 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5555 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5556 return Result;
5557 }
5558
John McCall0ad16662009-10-29 08:12:44 +00005559 TemplateSpecializationTypeLoc NewTL
5560 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005561 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005562 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5563 NewTL.setLAngleLoc(TL.getLAngleLoc());
5564 NewTL.setRAngleLoc(TL.getRAngleLoc());
5565 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5566 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005567 }
Mike Stump11289f42009-09-09 15:08:12 +00005568
John McCall0ad16662009-10-29 08:12:44 +00005569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregor5a064722011-02-28 17:23:35 +00005572template <typename Derived>
5573QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5574 TypeLocBuilder &TLB,
5575 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005576 TemplateName Template,
5577 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005578 TemplateArgumentListInfo NewTemplateArgs;
5579 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5580 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5581 typedef TemplateArgumentLocContainerIterator<
5582 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005583 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005584 ArgIterator(TL, TL.getNumArgs()),
5585 NewTemplateArgs))
5586 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005587
Douglas Gregor5a064722011-02-28 17:23:35 +00005588 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005589
Douglas Gregor5a064722011-02-28 17:23:35 +00005590 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5591 QualType Result
5592 = getSema().Context.getDependentTemplateSpecializationType(
5593 TL.getTypePtr()->getKeyword(),
5594 DTN->getQualifier(),
5595 DTN->getIdentifier(),
5596 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005597
Douglas Gregor5a064722011-02-28 17:23:35 +00005598 DependentTemplateSpecializationTypeLoc NewTL
5599 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005600 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005601 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005602 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005603 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005604 NewTL.setLAngleLoc(TL.getLAngleLoc());
5605 NewTL.setRAngleLoc(TL.getRAngleLoc());
5606 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5607 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5608 return Result;
5609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005610
5611 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005612 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005613 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005614 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005615
Douglas Gregor5a064722011-02-28 17:23:35 +00005616 if (!Result.isNull()) {
5617 /// FIXME: Wrap this in an elaborated-type-specifier?
5618 TemplateSpecializationTypeLoc NewTL
5619 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005620 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005621 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005622 NewTL.setLAngleLoc(TL.getLAngleLoc());
5623 NewTL.setRAngleLoc(TL.getRAngleLoc());
5624 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5625 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005627
Douglas Gregor5a064722011-02-28 17:23:35 +00005628 return Result;
5629}
5630
Mike Stump11289f42009-09-09 15:08:12 +00005631template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005632QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005633TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005634 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005635 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005636
Douglas Gregor844cb502011-03-01 18:12:44 +00005637 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005638 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005639 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005640 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005641 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5642 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005643 return QualType();
5644 }
Mike Stump11289f42009-09-09 15:08:12 +00005645
John McCall31f82722010-11-12 08:19:04 +00005646 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5647 if (NamedT.isNull())
5648 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005649
Richard Smith3f1b5d02011-05-05 21:57:07 +00005650 // C++0x [dcl.type.elab]p2:
5651 // If the identifier resolves to a typedef-name or the simple-template-id
5652 // resolves to an alias template specialization, the
5653 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005654 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5655 if (const TemplateSpecializationType *TST =
5656 NamedT->getAs<TemplateSpecializationType>()) {
5657 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005658 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5659 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005660 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5661 diag::err_tag_reference_non_tag) << 4;
5662 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5663 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005664 }
5665 }
5666
John McCall550e0c22009-10-21 00:40:46 +00005667 QualType Result = TL.getType();
5668 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005669 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005670 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005671 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005672 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005673 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005674 if (Result.isNull())
5675 return QualType();
5676 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005677
Abramo Bagnara6150c882010-05-11 21:36:43 +00005678 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005679 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005680 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005681 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005682}
Mike Stump11289f42009-09-09 15:08:12 +00005683
5684template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005685QualType TreeTransform<Derived>::TransformAttributedType(
5686 TypeLocBuilder &TLB,
5687 AttributedTypeLoc TL) {
5688 const AttributedType *oldType = TL.getTypePtr();
5689 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5690 if (modifiedType.isNull())
5691 return QualType();
5692
5693 QualType result = TL.getType();
5694
5695 // FIXME: dependent operand expressions?
5696 if (getDerived().AlwaysRebuild() ||
5697 modifiedType != oldType->getModifiedType()) {
5698 // TODO: this is really lame; we should really be rebuilding the
5699 // equivalent type from first principles.
5700 QualType equivalentType
5701 = getDerived().TransformType(oldType->getEquivalentType());
5702 if (equivalentType.isNull())
5703 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005704
5705 // Check whether we can add nullability; it is only represented as
5706 // type sugar, and therefore cannot be diagnosed in any other way.
5707 if (auto nullability = oldType->getImmediateNullability()) {
5708 if (!modifiedType->canHaveNullability()) {
5709 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005710 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005711 return QualType();
5712 }
5713 }
5714
John McCall81904512011-01-06 01:58:22 +00005715 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5716 modifiedType,
5717 equivalentType);
5718 }
5719
5720 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5721 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5722 if (TL.hasAttrOperand())
5723 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5724 if (TL.hasAttrExprOperand())
5725 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5726 else if (TL.hasAttrEnumOperand())
5727 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5728
5729 return result;
5730}
5731
5732template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005733QualType
5734TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5735 ParenTypeLoc TL) {
5736 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5737 if (Inner.isNull())
5738 return QualType();
5739
5740 QualType Result = TL.getType();
5741 if (getDerived().AlwaysRebuild() ||
5742 Inner != TL.getInnerLoc().getType()) {
5743 Result = getDerived().RebuildParenType(Inner);
5744 if (Result.isNull())
5745 return QualType();
5746 }
5747
5748 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5749 NewTL.setLParenLoc(TL.getLParenLoc());
5750 NewTL.setRParenLoc(TL.getRParenLoc());
5751 return Result;
5752}
5753
5754template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005755QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005756 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005757 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005758
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005759 NestedNameSpecifierLoc QualifierLoc
5760 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5761 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005763
John McCallc392f372010-06-11 00:33:02 +00005764 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005765 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005766 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005767 QualifierLoc,
5768 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005769 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005770 if (Result.isNull())
5771 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005772
Abramo Bagnarad7548482010-05-19 21:37:53 +00005773 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5774 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005775 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5776
Abramo Bagnarad7548482010-05-19 21:37:53 +00005777 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005778 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005779 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005780 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005781 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005782 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005783 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005784 NewTL.setNameLoc(TL.getNameLoc());
5785 }
John McCall550e0c22009-10-21 00:40:46 +00005786 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005790QualType TreeTransform<Derived>::
5791 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005792 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005793 NestedNameSpecifierLoc QualifierLoc;
5794 if (TL.getQualifierLoc()) {
5795 QualifierLoc
5796 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5797 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005798 return QualType();
5799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005800
John McCall31f82722010-11-12 08:19:04 +00005801 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005802 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005803}
5804
5805template<typename Derived>
5806QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005807TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5808 DependentTemplateSpecializationTypeLoc TL,
5809 NestedNameSpecifierLoc QualifierLoc) {
5810 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Douglas Gregora7a795b2011-03-01 20:11:18 +00005812 TemplateArgumentListInfo NewTemplateArgs;
5813 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5814 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005815
Douglas Gregora7a795b2011-03-01 20:11:18 +00005816 typedef TemplateArgumentLocContainerIterator<
5817 DependentTemplateSpecializationTypeLoc> ArgIterator;
5818 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5819 ArgIterator(TL, TL.getNumArgs()),
5820 NewTemplateArgs))
5821 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Douglas Gregora7a795b2011-03-01 20:11:18 +00005823 QualType Result
5824 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5825 QualifierLoc,
5826 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005827 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005828 NewTemplateArgs);
5829 if (Result.isNull())
5830 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005831
Douglas Gregora7a795b2011-03-01 20:11:18 +00005832 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5833 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregora7a795b2011-03-01 20:11:18 +00005835 // Copy information relevant to the template specialization.
5836 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005837 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005838 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005839 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005840 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5841 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005842 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005843 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Douglas Gregora7a795b2011-03-01 20:11:18 +00005845 // Copy information relevant to the elaborated type.
5846 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005847 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005848 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005849 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5850 DependentTemplateSpecializationTypeLoc SpecTL
5851 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005852 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005853 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005854 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005855 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005856 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5857 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005858 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005859 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005860 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005861 TemplateSpecializationTypeLoc SpecTL
5862 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005863 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005864 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005865 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5866 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005867 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005868 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005869 }
5870 return Result;
5871}
5872
5873template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005874QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5875 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005876 QualType Pattern
5877 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005878 if (Pattern.isNull())
5879 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
5881 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005882 if (getDerived().AlwaysRebuild() ||
5883 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005884 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005885 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005886 TL.getEllipsisLoc(),
5887 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005888 if (Result.isNull())
5889 return QualType();
5890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
Douglas Gregor822d0302011-01-12 17:07:58 +00005892 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5893 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5894 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005895}
5896
5897template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005898QualType
5899TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005900 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005901 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005902 TLB.pushFullCopy(TL);
5903 return TL.getType();
5904}
5905
5906template<typename Derived>
5907QualType
5908TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005909 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005910 // Transform base type.
5911 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5912 if (BaseType.isNull())
5913 return QualType();
5914
5915 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5916
5917 // Transform type arguments.
5918 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5919 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5920 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5921 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5922 QualType TypeArg = TypeArgInfo->getType();
5923 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5924 AnyChanged = true;
5925
5926 // We have a pack expansion. Instantiate it.
5927 const auto *PackExpansion = PackExpansionLoc.getType()
5928 ->castAs<PackExpansionType>();
5929 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5930 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5931 Unexpanded);
5932 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5933
5934 // Determine whether the set of unexpanded parameter packs can
5935 // and should be expanded.
5936 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5937 bool Expand = false;
5938 bool RetainExpansion = false;
5939 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5940 if (getDerived().TryExpandParameterPacks(
5941 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5942 Unexpanded, Expand, RetainExpansion, NumExpansions))
5943 return QualType();
5944
5945 if (!Expand) {
5946 // We can't expand this pack expansion into separate arguments yet;
5947 // just substitute into the pattern and create a new pack expansion
5948 // type.
5949 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5950
5951 TypeLocBuilder TypeArgBuilder;
5952 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5953 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5954 PatternLoc);
5955 if (NewPatternType.isNull())
5956 return QualType();
5957
5958 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5959 NewPatternType, NumExpansions);
5960 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5961 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5962 NewTypeArgInfos.push_back(
5963 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5964 continue;
5965 }
5966
5967 // Substitute into the pack expansion pattern for each slice of the
5968 // pack.
5969 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5970 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5971
5972 TypeLocBuilder TypeArgBuilder;
5973 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5974
5975 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5976 PatternLoc);
5977 if (NewTypeArg.isNull())
5978 return QualType();
5979
5980 NewTypeArgInfos.push_back(
5981 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5982 }
5983
5984 continue;
5985 }
5986
5987 TypeLocBuilder TypeArgBuilder;
5988 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5989 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5990 if (NewTypeArg.isNull())
5991 return QualType();
5992
5993 // If nothing changed, just keep the old TypeSourceInfo.
5994 if (NewTypeArg == TypeArg) {
5995 NewTypeArgInfos.push_back(TypeArgInfo);
5996 continue;
5997 }
5998
5999 NewTypeArgInfos.push_back(
6000 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6001 AnyChanged = true;
6002 }
6003
6004 QualType Result = TL.getType();
6005 if (getDerived().AlwaysRebuild() || AnyChanged) {
6006 // Rebuild the type.
6007 Result = getDerived().RebuildObjCObjectType(
6008 BaseType,
6009 TL.getLocStart(),
6010 TL.getTypeArgsLAngleLoc(),
6011 NewTypeArgInfos,
6012 TL.getTypeArgsRAngleLoc(),
6013 TL.getProtocolLAngleLoc(),
6014 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6015 TL.getNumProtocols()),
6016 TL.getProtocolLocs(),
6017 TL.getProtocolRAngleLoc());
6018
6019 if (Result.isNull())
6020 return QualType();
6021 }
6022
6023 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006024 NewT.setHasBaseTypeAsWritten(true);
6025 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6026 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6027 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6028 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6029 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6030 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6031 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6032 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6033 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006034}
Mike Stump11289f42009-09-09 15:08:12 +00006035
6036template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006037QualType
6038TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006039 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006040 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6041 if (PointeeType.isNull())
6042 return QualType();
6043
6044 QualType Result = TL.getType();
6045 if (getDerived().AlwaysRebuild() ||
6046 PointeeType != TL.getPointeeLoc().getType()) {
6047 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6048 TL.getStarLoc());
6049 if (Result.isNull())
6050 return QualType();
6051 }
6052
6053 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6054 NewT.setStarLoc(TL.getStarLoc());
6055 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006056}
6057
Douglas Gregord6ff3322009-08-04 16:50:30 +00006058//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006059// Statement transformation
6060//===----------------------------------------------------------------------===//
6061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006063TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006064 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006065}
6066
6067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006068StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006069TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6070 return getDerived().TransformCompoundStmt(S, false);
6071}
6072
6073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006074StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006075TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006077 Sema::CompoundScopeRAII CompoundScope(getSema());
6078
John McCall1ababa62010-08-27 19:56:05 +00006079 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006081 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006082 for (auto *B : S->body()) {
6083 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006084 if (Result.isInvalid()) {
6085 // Immediately fail if this was a DeclStmt, since it's very
6086 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006087 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006088 return StmtError();
6089
6090 // Otherwise, just keep processing substatements and fail later.
6091 SubStmtInvalid = true;
6092 continue;
6093 }
Mike Stump11289f42009-09-09 15:08:12 +00006094
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006095 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006096 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006097 }
Mike Stump11289f42009-09-09 15:08:12 +00006098
John McCall1ababa62010-08-27 19:56:05 +00006099 if (SubStmtInvalid)
6100 return StmtError();
6101
Douglas Gregorebe10102009-08-20 07:17:43 +00006102 if (!getDerived().AlwaysRebuild() &&
6103 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006104 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006105
6106 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006107 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006108 S->getRBracLoc(),
6109 IsStmtExpr);
6110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregorebe10102009-08-20 07:17:43 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006114TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006116 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006117 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6118 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006119
Eli Friedman06577382009-11-19 03:14:00 +00006120 // Transform the left-hand case value.
6121 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006122 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006123 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006125
Eli Friedman06577382009-11-19 03:14:00 +00006126 // Transform the right-hand case value (for the GNU case-range extension).
6127 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006128 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006129 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006131 }
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregorebe10102009-08-20 07:17:43 +00006133 // Build the case statement.
6134 // Case statements are always rebuilt so that they will attached to their
6135 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006136 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006137 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006138 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006139 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006140 S->getColonLoc());
6141 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006145 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006146 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006150 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006151}
6152
6153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006155TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006156 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006157 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006158 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 // Default statements are always rebuilt
6162 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006163 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006164}
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregorebe10102009-08-20 07:17:43 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006168TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006169 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
Chris Lattnercab02a62011-02-17 20:34:02 +00006173 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6174 S->getDecl());
6175 if (!LD)
6176 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006177
6178
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006180 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006181 cast<LabelDecl>(LD), SourceLocation(),
6182 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006183}
Mike Stump11289f42009-09-09 15:08:12 +00006184
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006185template <typename Derived>
6186const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6187 if (!R)
6188 return R;
6189
6190 switch (R->getKind()) {
6191// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6192#define ATTR(X)
6193#define PRAGMA_SPELLING_ATTR(X) \
6194 case attr::X: \
6195 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6196#include "clang/Basic/AttrList.inc"
6197 default:
6198 return R;
6199 }
6200}
6201
6202template <typename Derived>
6203StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6204 bool AttrsChanged = false;
6205 SmallVector<const Attr *, 1> Attrs;
6206
6207 // Visit attributes and keep track if any are transformed.
6208 for (const auto *I : S->getAttrs()) {
6209 const Attr *R = getDerived().TransformAttr(I);
6210 AttrsChanged |= (I != R);
6211 Attrs.push_back(R);
6212 }
6213
Richard Smithc202b282012-04-14 00:33:13 +00006214 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6215 if (SubStmt.isInvalid())
6216 return StmtError();
6217
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006218 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006219 return S;
6220
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006221 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006222 SubStmt.get());
6223}
6224
6225template<typename Derived>
6226StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006227TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006228 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006229 Sema::ConditionResult Cond = getDerived().TransformCondition(
6230 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006231 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6232 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006233 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006234 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006235
Richard Smithb130fe72016-06-23 19:16:49 +00006236 // If this is a constexpr if, determine which arm we should instantiate.
6237 llvm::Optional<bool> ConstexprConditionValue;
6238 if (S->isConstexpr())
6239 ConstexprConditionValue = Cond.getKnownValue();
6240
Douglas Gregorebe10102009-08-20 07:17:43 +00006241 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006242 StmtResult Then;
6243 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6244 Then = getDerived().TransformStmt(S->getThen());
6245 if (Then.isInvalid())
6246 return StmtError();
6247 } else {
6248 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6249 }
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregorebe10102009-08-20 07:17:43 +00006251 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006252 StmtResult Else;
6253 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6254 Else = getDerived().TransformStmt(S->getElse());
6255 if (Else.isInvalid())
6256 return StmtError();
6257 }
Mike Stump11289f42009-09-09 15:08:12 +00006258
Douglas Gregorebe10102009-08-20 07:17:43 +00006259 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006260 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006261 Then.get() == S->getThen() &&
6262 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006263 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006264
Richard Smithb130fe72016-06-23 19:16:49 +00006265 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6266 Then.get(), S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006267}
6268
6269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006270StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006271TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006272 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006273 Sema::ConditionResult Cond = getDerived().TransformCondition(
6274 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6275 Sema::ConditionKind::Switch);
6276 if (Cond.isInvalid())
6277 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregorebe10102009-08-20 07:17:43 +00006279 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006280 StmtResult Switch
Richard Smith03a4aa32016-06-23 19:02:52 +00006281 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006282 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006284
Douglas Gregorebe10102009-08-20 07:17:43 +00006285 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006286 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006287 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregorebe10102009-08-20 07:17:43 +00006290 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006291 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6292 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006293}
Mike Stump11289f42009-09-09 15:08:12 +00006294
Douglas Gregorebe10102009-08-20 07:17:43 +00006295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006296StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006297TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006299 Sema::ConditionResult Cond = getDerived().TransformCondition(
6300 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6301 Sema::ConditionKind::Boolean);
6302 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006303 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006304
Douglas Gregorebe10102009-08-20 07:17:43 +00006305 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006306 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006307 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006308 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregorebe10102009-08-20 07:17:43 +00006310 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006311 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006312 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006313 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006314
Richard Smith03a4aa32016-06-23 19:02:52 +00006315 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006316}
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregorebe10102009-08-20 07:17:43 +00006318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006319StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006320TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006321 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006322 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006323 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006324 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006326 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006327 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006328 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006330
Douglas Gregorebe10102009-08-20 07:17:43 +00006331 if (!getDerived().AlwaysRebuild() &&
6332 Cond.get() == S->getCond() &&
6333 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006334 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006335
John McCallb268a282010-08-23 23:25:46 +00006336 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6337 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006338 S->getRParenLoc());
6339}
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregorebe10102009-08-20 07:17:43 +00006341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006342StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006343TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006344 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006345 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006346 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006347 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006348
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006349 // In OpenMP loop region loop control variable must be captured and be
6350 // private. Perform analysis of first part (if any).
6351 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6352 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6353
Douglas Gregorebe10102009-08-20 07:17:43 +00006354 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006355 Sema::ConditionResult Cond = getDerived().TransformCondition(
6356 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6357 Sema::ConditionKind::Boolean);
6358 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006359 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006360
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006362 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006363 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006365
Richard Smith945f8d32013-01-14 22:39:08 +00006366 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006367 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006368 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006369
Douglas Gregorebe10102009-08-20 07:17:43 +00006370 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006371 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006373 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregorebe10102009-08-20 07:17:43 +00006375 if (!getDerived().AlwaysRebuild() &&
6376 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006377 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006378 Inc.get() == S->getInc() &&
6379 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006380 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregorebe10102009-08-20 07:17:43 +00006382 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006383 Init.get(), Cond, FullInc,
6384 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006385}
6386
6387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006388StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006389TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006390 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6391 S->getLabel());
6392 if (!LD)
6393 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006394
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006396 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006397 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006398}
6399
6400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006401StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006402TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006403 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006406 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 if (!getDerived().AlwaysRebuild() &&
6409 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006410 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006411
6412 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006413 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006414}
6415
6416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006417StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006418TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006419 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregorebe10102009-08-20 07:17:43 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006424TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006425 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006426}
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregorebe10102009-08-20 07:17:43 +00006428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006429StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006430TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006431 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6432 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006435
Mike Stump11289f42009-09-09 15:08:12 +00006436 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006437 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006438 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006439}
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregorebe10102009-08-20 07:17:43 +00006441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006443TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006445 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006446 for (auto *D : S->decls()) {
6447 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006448 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006449 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006450
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006451 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006452 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregorebe10102009-08-20 07:17:43 +00006454 Decls.push_back(Transformed);
6455 }
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006458 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006459
Rafael Espindolaab417692013-07-09 12:05:01 +00006460 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006461}
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregorebe10102009-08-20 07:17:43 +00006463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006464StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006465TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006466
Benjamin Kramerf0623432012-08-23 22:51:59 +00006467 SmallVector<Expr*, 8> Constraints;
6468 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006469 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006470
John McCalldadc5752010-08-24 06:29:42 +00006471 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006472 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006473
6474 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006475
Anders Carlssonaaeef072010-01-24 05:50:09 +00006476 // Go through the outputs.
6477 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006478 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006479
Anders Carlssonaaeef072010-01-24 05:50:09 +00006480 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006481 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006482
Anders Carlssonaaeef072010-01-24 05:50:09 +00006483 // Transform the output expr.
6484 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006485 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006486 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006487 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006488
Anders Carlssonaaeef072010-01-24 05:50:09 +00006489 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006490
John McCallb268a282010-08-23 23:25:46 +00006491 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006493
Anders Carlssonaaeef072010-01-24 05:50:09 +00006494 // Go through the inputs.
6495 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006496 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006497
Anders Carlssonaaeef072010-01-24 05:50:09 +00006498 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006499 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006500
Anders Carlssonaaeef072010-01-24 05:50:09 +00006501 // Transform the input expr.
6502 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006503 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006504 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006505 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006506
Anders Carlssonaaeef072010-01-24 05:50:09 +00006507 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006508
John McCallb268a282010-08-23 23:25:46 +00006509 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006511
Anders Carlssonaaeef072010-01-24 05:50:09 +00006512 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006513 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006514
6515 // Go through the clobbers.
6516 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006517 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006518
6519 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006520 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006521 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6522 S->isVolatile(), S->getNumOutputs(),
6523 S->getNumInputs(), Names.data(),
6524 Constraints, Exprs, AsmString.get(),
6525 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006526}
6527
Chad Rosier32503022012-06-11 20:47:18 +00006528template<typename Derived>
6529StmtResult
6530TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006531 ArrayRef<Token> AsmToks =
6532 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006533
John McCallf413f5e2013-05-03 00:10:13 +00006534 bool HadError = false, HadChange = false;
6535
6536 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6537 SmallVector<Expr*, 8> TransformedExprs;
6538 TransformedExprs.reserve(SrcExprs.size());
6539 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6540 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6541 if (!Result.isUsable()) {
6542 HadError = true;
6543 } else {
6544 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006545 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006546 }
6547 }
6548
6549 if (HadError) return StmtError();
6550 if (!HadChange && !getDerived().AlwaysRebuild())
6551 return Owned(S);
6552
Chad Rosierb6f46c12012-08-15 16:53:30 +00006553 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006554 AsmToks, S->getAsmString(),
6555 S->getNumOutputs(), S->getNumInputs(),
6556 S->getAllConstraints(), S->getClobbers(),
6557 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006558}
Douglas Gregorebe10102009-08-20 07:17:43 +00006559
Richard Smith9f690bd2015-10-27 06:02:45 +00006560// C++ Coroutines TS
6561
6562template<typename Derived>
6563StmtResult
6564TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6565 // The coroutine body should be re-formed by the caller if necessary.
6566 return getDerived().TransformStmt(S->getBody());
6567}
6568
6569template<typename Derived>
6570StmtResult
6571TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6572 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6573 /*NotCopyInit*/false);
6574 if (Result.isInvalid())
6575 return StmtError();
6576
6577 // Always rebuild; we don't know if this needs to be injected into a new
6578 // context or if the promise type has changed.
6579 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6580}
6581
6582template<typename Derived>
6583ExprResult
6584TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6585 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6586 /*NotCopyInit*/false);
6587 if (Result.isInvalid())
6588 return ExprError();
6589
6590 // Always rebuild; we don't know if this needs to be injected into a new
6591 // context or if the promise type has changed.
6592 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6593}
6594
6595template<typename Derived>
6596ExprResult
6597TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6598 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6599 /*NotCopyInit*/false);
6600 if (Result.isInvalid())
6601 return ExprError();
6602
6603 // Always rebuild; we don't know if this needs to be injected into a new
6604 // context or if the promise type has changed.
6605 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6606}
6607
6608// Objective-C Statements.
6609
Douglas Gregorebe10102009-08-20 07:17:43 +00006610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006612TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006613 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006614 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006615 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006617
Douglas Gregor96c79492010-04-23 22:50:49 +00006618 // Transform the @catch statements (if present).
6619 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006620 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006621 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006622 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006623 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006625 if (Catch.get() != S->getCatchStmt(I))
6626 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006627 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006629
Douglas Gregor306de2f2010-04-22 23:59:56 +00006630 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006631 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006632 if (S->getFinallyStmt()) {
6633 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6634 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006635 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006636 }
6637
6638 // If nothing changed, just retain this statement.
6639 if (!getDerived().AlwaysRebuild() &&
6640 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006641 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006642 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006643 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006644
Douglas Gregor306de2f2010-04-22 23:59:56 +00006645 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006646 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006647 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006648}
Mike Stump11289f42009-09-09 15:08:12 +00006649
Douglas Gregorebe10102009-08-20 07:17:43 +00006650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006651StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006652TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006653 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006654 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006655 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006656 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006657 if (FromVar->getTypeSourceInfo()) {
6658 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6659 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006662
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006663 QualType T;
6664 if (TSInfo)
6665 T = TSInfo->getType();
6666 else {
6667 T = getDerived().TransformType(FromVar->getType());
6668 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006669 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006671
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006672 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6673 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006674 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006676
John McCalldadc5752010-08-24 06:29:42 +00006677 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006678 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006680
6681 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006682 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006683 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006684}
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregorebe10102009-08-20 07:17:43 +00006686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006688TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006689 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006690 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006691 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006693
Douglas Gregor306de2f2010-04-22 23:59:56 +00006694 // If nothing changed, just retain this statement.
6695 if (!getDerived().AlwaysRebuild() &&
6696 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006697 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006698
6699 // Build a new statement.
6700 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006701 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006702}
Mike Stump11289f42009-09-09 15:08:12 +00006703
Douglas Gregorebe10102009-08-20 07:17:43 +00006704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006706TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006707 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006708 if (S->getThrowExpr()) {
6709 Operand = getDerived().TransformExpr(S->getThrowExpr());
6710 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006711 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006713
Douglas Gregor2900c162010-04-22 21:44:01 +00006714 if (!getDerived().AlwaysRebuild() &&
6715 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006716 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
John McCallb268a282010-08-23 23:25:46 +00006718 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregorebe10102009-08-20 07:17:43 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006723TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006724 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006725 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006726 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006727 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006729 Object =
6730 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6731 Object.get());
6732 if (Object.isInvalid())
6733 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregor6148de72010-04-22 22:01:21 +00006735 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006736 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006737 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006738 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006739
Douglas Gregor6148de72010-04-22 22:01:21 +00006740 // If nothing change, just retain the current statement.
6741 if (!getDerived().AlwaysRebuild() &&
6742 Object.get() == S->getSynchExpr() &&
6743 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006744 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006745
6746 // Build a new statement.
6747 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006748 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006749}
6750
6751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006752StmtResult
John McCall31168b02011-06-15 23:02:42 +00006753TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6754 ObjCAutoreleasePoolStmt *S) {
6755 // Transform the body.
6756 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6757 if (Body.isInvalid())
6758 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
John McCall31168b02011-06-15 23:02:42 +00006760 // If nothing changed, just retain this statement.
6761 if (!getDerived().AlwaysRebuild() &&
6762 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006763 return S;
John McCall31168b02011-06-15 23:02:42 +00006764
6765 // Build a new statement.
6766 return getDerived().RebuildObjCAutoreleasePoolStmt(
6767 S->getAtLoc(), Body.get());
6768}
6769
6770template<typename Derived>
6771StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006772TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006773 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006774 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006775 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006776 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006778
Douglas Gregorf68a5082010-04-22 23:10:45 +00006779 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006780 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006781 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Douglas Gregorf68a5082010-04-22 23:10:45 +00006784 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006785 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006786 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregorf68a5082010-04-22 23:10:45 +00006789 // If nothing changed, just retain this statement.
6790 if (!getDerived().AlwaysRebuild() &&
6791 Element.get() == S->getElement() &&
6792 Collection.get() == S->getCollection() &&
6793 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006794 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006795
Douglas Gregorf68a5082010-04-22 23:10:45 +00006796 // Build a new statement.
6797 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006798 Element.get(),
6799 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006800 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006801 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006802}
6803
David Majnemer5f7efef2013-10-15 09:50:08 +00006804template <typename Derived>
6805StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006806 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006807 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006808 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6809 TypeSourceInfo *T =
6810 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006811 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006813
David Majnemer5f7efef2013-10-15 09:50:08 +00006814 Var = getDerived().RebuildExceptionDecl(
6815 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6816 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006817 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006818 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006819 }
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregorebe10102009-08-20 07:17:43 +00006821 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006822 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006823 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006824 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006825
David Majnemer5f7efef2013-10-15 09:50:08 +00006826 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006827 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006828 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006829
David Majnemer5f7efef2013-10-15 09:50:08 +00006830 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006831}
Mike Stump11289f42009-09-09 15:08:12 +00006832
David Majnemer5f7efef2013-10-15 09:50:08 +00006833template <typename Derived>
6834StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006835 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006836 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006837 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006838 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregorebe10102009-08-20 07:17:43 +00006840 // Transform the handlers.
6841 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006842 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006843 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006844 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006845 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006846 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregorebe10102009-08-20 07:17:43 +00006848 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006849 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006850 }
Mike Stump11289f42009-09-09 15:08:12 +00006851
David Majnemer5f7efef2013-10-15 09:50:08 +00006852 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006853 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006854 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006855
John McCallb268a282010-08-23 23:25:46 +00006856 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006857 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006858}
Mike Stump11289f42009-09-09 15:08:12 +00006859
Richard Smith02e85f32011-04-14 22:09:26 +00006860template<typename Derived>
6861StmtResult
6862TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6863 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6864 if (Range.isInvalid())
6865 return StmtError();
6866
Richard Smith01694c32016-03-20 10:33:40 +00006867 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6868 if (Begin.isInvalid())
6869 return StmtError();
6870 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6871 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006872 return StmtError();
6873
6874 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6875 if (Cond.isInvalid())
6876 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006877 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006878 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006879 if (Cond.isInvalid())
6880 return StmtError();
6881 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006882 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006883
6884 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6885 if (Inc.isInvalid())
6886 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006887 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006888 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006889
6890 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6891 if (LoopVar.isInvalid())
6892 return StmtError();
6893
6894 StmtResult NewStmt = S;
6895 if (getDerived().AlwaysRebuild() ||
6896 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006897 Begin.get() != S->getBeginStmt() ||
6898 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006899 Cond.get() != S->getCond() ||
6900 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006901 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006902 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006903 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006904 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006905 Begin.get(), End.get(),
6906 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006907 Inc.get(), LoopVar.get(),
6908 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006909 if (NewStmt.isInvalid())
6910 return StmtError();
6911 }
Richard Smith02e85f32011-04-14 22:09:26 +00006912
6913 StmtResult Body = getDerived().TransformStmt(S->getBody());
6914 if (Body.isInvalid())
6915 return StmtError();
6916
6917 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6918 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006919 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006920 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006921 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006922 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006923 Begin.get(), End.get(),
6924 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006925 Inc.get(), LoopVar.get(),
6926 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006927 if (NewStmt.isInvalid())
6928 return StmtError();
6929 }
Richard Smith02e85f32011-04-14 22:09:26 +00006930
6931 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006932 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006933
6934 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6935}
6936
John Wiegley1c0675e2011-04-28 01:08:34 +00006937template<typename Derived>
6938StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006939TreeTransform<Derived>::TransformMSDependentExistsStmt(
6940 MSDependentExistsStmt *S) {
6941 // Transform the nested-name-specifier, if any.
6942 NestedNameSpecifierLoc QualifierLoc;
6943 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006944 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006945 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6946 if (!QualifierLoc)
6947 return StmtError();
6948 }
6949
6950 // Transform the declaration name.
6951 DeclarationNameInfo NameInfo = S->getNameInfo();
6952 if (NameInfo.getName()) {
6953 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6954 if (!NameInfo.getName())
6955 return StmtError();
6956 }
6957
6958 // Check whether anything changed.
6959 if (!getDerived().AlwaysRebuild() &&
6960 QualifierLoc == S->getQualifierLoc() &&
6961 NameInfo.getName() == S->getNameInfo().getName())
6962 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006963
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006964 // Determine whether this name exists, if we can.
6965 CXXScopeSpec SS;
6966 SS.Adopt(QualifierLoc);
6967 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006968 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006969 case Sema::IER_Exists:
6970 if (S->isIfExists())
6971 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006972
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006973 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6974
6975 case Sema::IER_DoesNotExist:
6976 if (S->isIfNotExists())
6977 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006978
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006979 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006980
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006981 case Sema::IER_Dependent:
6982 Dependent = true;
6983 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006984
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006985 case Sema::IER_Error:
6986 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006988
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006989 // We need to continue with the instantiation, so do so now.
6990 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6991 if (SubStmt.isInvalid())
6992 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006993
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006994 // If we have resolved the name, just transform to the substatement.
6995 if (!Dependent)
6996 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006997
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006998 // The name is still dependent, so build a dependent expression again.
6999 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7000 S->isIfExists(),
7001 QualifierLoc,
7002 NameInfo,
7003 SubStmt.get());
7004}
7005
7006template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007007ExprResult
7008TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7009 NestedNameSpecifierLoc QualifierLoc;
7010 if (E->getQualifierLoc()) {
7011 QualifierLoc
7012 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7013 if (!QualifierLoc)
7014 return ExprError();
7015 }
7016
7017 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7018 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7019 if (!PD)
7020 return ExprError();
7021
7022 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7023 if (Base.isInvalid())
7024 return ExprError();
7025
7026 return new (SemaRef.getASTContext())
7027 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7028 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7029 QualifierLoc, E->getMemberLoc());
7030}
7031
David Majnemerfad8f482013-10-15 09:33:02 +00007032template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007033ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7034 MSPropertySubscriptExpr *E) {
7035 auto BaseRes = getDerived().TransformExpr(E->getBase());
7036 if (BaseRes.isInvalid())
7037 return ExprError();
7038 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7039 if (IdxRes.isInvalid())
7040 return ExprError();
7041
7042 if (!getDerived().AlwaysRebuild() &&
7043 BaseRes.get() == E->getBase() &&
7044 IdxRes.get() == E->getIdx())
7045 return E;
7046
7047 return getDerived().RebuildArraySubscriptExpr(
7048 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7049}
7050
7051template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007052StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007053 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007054 if (TryBlock.isInvalid())
7055 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007056
7057 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007058 if (Handler.isInvalid())
7059 return StmtError();
7060
David Majnemerfad8f482013-10-15 09:33:02 +00007061 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7062 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007063 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007064
Warren Huntf6be4cb2014-07-25 20:52:51 +00007065 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7066 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007067}
7068
David Majnemerfad8f482013-10-15 09:33:02 +00007069template <typename Derived>
7070StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007071 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007072 if (Block.isInvalid())
7073 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007074
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007075 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007076}
7077
David Majnemerfad8f482013-10-15 09:33:02 +00007078template <typename Derived>
7079StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007080 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007081 if (FilterExpr.isInvalid())
7082 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007083
David Majnemer7e755502013-10-15 09:30:14 +00007084 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007085 if (Block.isInvalid())
7086 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007087
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007088 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7089 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007090}
7091
David Majnemerfad8f482013-10-15 09:33:02 +00007092template <typename Derived>
7093StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7094 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007095 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7096 else
7097 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7098}
7099
Nico Weber9b982072014-07-07 00:12:30 +00007100template<typename Derived>
7101StmtResult
7102TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7103 return S;
7104}
7105
Alexander Musman64d33f12014-06-04 07:53:32 +00007106//===----------------------------------------------------------------------===//
7107// OpenMP directive transformation
7108//===----------------------------------------------------------------------===//
7109template <typename Derived>
7110StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7111 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007112
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007113 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007114 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007115 ArrayRef<OMPClause *> Clauses = D->clauses();
7116 TClauses.reserve(Clauses.size());
7117 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7118 I != E; ++I) {
7119 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007120 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007121 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007122 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007123 if (Clause)
7124 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007125 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007126 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007127 }
7128 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007129 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007130 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007131 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7132 /*CurScope=*/nullptr);
7133 StmtResult Body;
7134 {
7135 Sema::CompoundScopeRAII CompoundScope(getSema());
7136 Body = getDerived().TransformStmt(
7137 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7138 }
7139 AssociatedStmt =
7140 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007141 if (AssociatedStmt.isInvalid()) {
7142 return StmtError();
7143 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007144 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007145 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007146 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007147 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007148
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007149 // Transform directive name for 'omp critical' directive.
7150 DeclarationNameInfo DirName;
7151 if (D->getDirectiveKind() == OMPD_critical) {
7152 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7153 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7154 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007155 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7156 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7157 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007158 } else if (D->getDirectiveKind() == OMPD_cancel) {
7159 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007160 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007161
Alexander Musman64d33f12014-06-04 07:53:32 +00007162 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007163 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7164 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007165}
7166
Alexander Musman64d33f12014-06-04 07:53:32 +00007167template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007168StmtResult
7169TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7170 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007171 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7172 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007173 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7174 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7175 return Res;
7176}
7177
Alexander Musman64d33f12014-06-04 07:53:32 +00007178template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007179StmtResult
7180TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7181 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007182 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7183 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007184 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7185 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007186 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007187}
7188
Alexey Bataevf29276e2014-06-18 04:14:57 +00007189template <typename Derived>
7190StmtResult
7191TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7192 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007193 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7194 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007195 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7196 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7197 return Res;
7198}
7199
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007200template <typename Derived>
7201StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007202TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7203 DeclarationNameInfo DirName;
7204 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7205 D->getLocStart());
7206 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7207 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7208 return Res;
7209}
7210
7211template <typename Derived>
7212StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007213TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7214 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007215 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7216 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007217 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7218 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7219 return Res;
7220}
7221
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007222template <typename Derived>
7223StmtResult
7224TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7225 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007226 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7227 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007228 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7229 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7230 return Res;
7231}
7232
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007233template <typename Derived>
7234StmtResult
7235TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7236 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007237 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7238 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007239 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7240 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7241 return Res;
7242}
7243
Alexey Bataev4acb8592014-07-07 13:01:15 +00007244template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007245StmtResult
7246TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7247 DeclarationNameInfo DirName;
7248 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7249 D->getLocStart());
7250 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7251 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7252 return Res;
7253}
7254
7255template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007256StmtResult
7257TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7258 getDerived().getSema().StartOpenMPDSABlock(
7259 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7260 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7261 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7262 return Res;
7263}
7264
7265template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007266StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7267 OMPParallelForDirective *D) {
7268 DeclarationNameInfo DirName;
7269 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7270 nullptr, D->getLocStart());
7271 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7272 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7273 return Res;
7274}
7275
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007276template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007277StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7278 OMPParallelForSimdDirective *D) {
7279 DeclarationNameInfo DirName;
7280 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7281 nullptr, D->getLocStart());
7282 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7283 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7284 return Res;
7285}
7286
7287template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007288StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7289 OMPParallelSectionsDirective *D) {
7290 DeclarationNameInfo DirName;
7291 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7292 nullptr, D->getLocStart());
7293 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7294 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7295 return Res;
7296}
7297
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007298template <typename Derived>
7299StmtResult
7300TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7301 DeclarationNameInfo DirName;
7302 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7303 D->getLocStart());
7304 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7305 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7306 return Res;
7307}
7308
Alexey Bataev68446b72014-07-18 07:47:19 +00007309template <typename Derived>
7310StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7311 OMPTaskyieldDirective *D) {
7312 DeclarationNameInfo DirName;
7313 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7314 D->getLocStart());
7315 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7316 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7317 return Res;
7318}
7319
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007320template <typename Derived>
7321StmtResult
7322TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7323 DeclarationNameInfo DirName;
7324 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7325 D->getLocStart());
7326 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7327 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7328 return Res;
7329}
7330
Alexey Bataev2df347a2014-07-18 10:17:07 +00007331template <typename Derived>
7332StmtResult
7333TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7334 DeclarationNameInfo DirName;
7335 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7336 D->getLocStart());
7337 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7338 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7339 return Res;
7340}
7341
Alexey Bataev6125da92014-07-21 11:26:11 +00007342template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007343StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7344 OMPTaskgroupDirective *D) {
7345 DeclarationNameInfo DirName;
7346 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7347 D->getLocStart());
7348 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7349 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7350 return Res;
7351}
7352
7353template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007354StmtResult
7355TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7356 DeclarationNameInfo DirName;
7357 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7358 D->getLocStart());
7359 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7360 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7361 return Res;
7362}
7363
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007364template <typename Derived>
7365StmtResult
7366TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7367 DeclarationNameInfo DirName;
7368 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7369 D->getLocStart());
7370 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7371 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7372 return Res;
7373}
7374
Alexey Bataev0162e452014-07-22 10:10:35 +00007375template <typename Derived>
7376StmtResult
7377TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7378 DeclarationNameInfo DirName;
7379 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7380 D->getLocStart());
7381 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7382 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7383 return Res;
7384}
7385
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007386template <typename Derived>
7387StmtResult
7388TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7389 DeclarationNameInfo DirName;
7390 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7391 D->getLocStart());
7392 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7393 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7394 return Res;
7395}
7396
Alexey Bataev13314bf2014-10-09 04:18:56 +00007397template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007398StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7399 OMPTargetDataDirective *D) {
7400 DeclarationNameInfo DirName;
7401 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7402 D->getLocStart());
7403 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7404 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7405 return Res;
7406}
7407
7408template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007409StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7410 OMPTargetEnterDataDirective *D) {
7411 DeclarationNameInfo DirName;
7412 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7413 nullptr, D->getLocStart());
7414 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7415 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7416 return Res;
7417}
7418
7419template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007420StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7421 OMPTargetExitDataDirective *D) {
7422 DeclarationNameInfo DirName;
7423 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7424 nullptr, D->getLocStart());
7425 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7426 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7427 return Res;
7428}
7429
7430template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007431StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7432 OMPTargetParallelDirective *D) {
7433 DeclarationNameInfo DirName;
7434 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7435 nullptr, D->getLocStart());
7436 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7437 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7438 return Res;
7439}
7440
7441template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007442StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7443 OMPTargetParallelForDirective *D) {
7444 DeclarationNameInfo DirName;
7445 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7446 nullptr, D->getLocStart());
7447 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7448 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7449 return Res;
7450}
7451
7452template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007453StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7454 OMPTargetUpdateDirective *D) {
7455 DeclarationNameInfo DirName;
7456 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7457 nullptr, D->getLocStart());
7458 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7459 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7460 return Res;
7461}
7462
7463template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007464StmtResult
7465TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7466 DeclarationNameInfo DirName;
7467 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7468 D->getLocStart());
7469 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7470 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7471 return Res;
7472}
7473
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007474template <typename Derived>
7475StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7476 OMPCancellationPointDirective *D) {
7477 DeclarationNameInfo DirName;
7478 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7479 nullptr, D->getLocStart());
7480 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7481 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7482 return Res;
7483}
7484
Alexey Bataev80909872015-07-02 11:25:17 +00007485template <typename Derived>
7486StmtResult
7487TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7488 DeclarationNameInfo DirName;
7489 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7490 D->getLocStart());
7491 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7492 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7493 return Res;
7494}
7495
Alexey Bataev49f6e782015-12-01 04:18:41 +00007496template <typename Derived>
7497StmtResult
7498TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7499 DeclarationNameInfo DirName;
7500 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7501 D->getLocStart());
7502 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7503 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7504 return Res;
7505}
7506
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007507template <typename Derived>
7508StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7509 OMPTaskLoopSimdDirective *D) {
7510 DeclarationNameInfo DirName;
7511 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7512 nullptr, D->getLocStart());
7513 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7514 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7515 return Res;
7516}
7517
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007518template <typename Derived>
7519StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7520 OMPDistributeDirective *D) {
7521 DeclarationNameInfo DirName;
7522 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7523 D->getLocStart());
7524 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7525 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7526 return Res;
7527}
7528
Carlo Bertolli9925f152016-06-27 14:55:37 +00007529template <typename Derived>
7530StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7531 OMPDistributeParallelForDirective *D) {
7532 DeclarationNameInfo DirName;
7533 getDerived().getSema().StartOpenMPDSABlock(
7534 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7535 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7536 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7537 return Res;
7538}
7539
Alexander Musman64d33f12014-06-04 07:53:32 +00007540//===----------------------------------------------------------------------===//
7541// OpenMP clause transformation
7542//===----------------------------------------------------------------------===//
7543template <typename Derived>
7544OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007545 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7546 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007547 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007548 return getDerived().RebuildOMPIfClause(
7549 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7550 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007551}
7552
Alexander Musman64d33f12014-06-04 07:53:32 +00007553template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007554OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7555 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7556 if (Cond.isInvalid())
7557 return nullptr;
7558 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7559 C->getLParenLoc(), C->getLocEnd());
7560}
7561
7562template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007563OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007564TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7565 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7566 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007567 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007568 return getDerived().RebuildOMPNumThreadsClause(
7569 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007570}
7571
Alexey Bataev62c87d22014-03-21 04:51:18 +00007572template <typename Derived>
7573OMPClause *
7574TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7575 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7576 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007577 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007578 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007579 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007580}
7581
Alexander Musman8bd31e62014-05-27 15:12:19 +00007582template <typename Derived>
7583OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007584TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7585 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7586 if (E.isInvalid())
7587 return nullptr;
7588 return getDerived().RebuildOMPSimdlenClause(
7589 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7590}
7591
7592template <typename Derived>
7593OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007594TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7595 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7596 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007597 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007598 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007599 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007600}
7601
Alexander Musman64d33f12014-06-04 07:53:32 +00007602template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007603OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007604TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007605 return getDerived().RebuildOMPDefaultClause(
7606 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7607 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007608}
7609
Alexander Musman64d33f12014-06-04 07:53:32 +00007610template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007611OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007612TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007613 return getDerived().RebuildOMPProcBindClause(
7614 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7615 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007616}
7617
Alexander Musman64d33f12014-06-04 07:53:32 +00007618template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007619OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007620TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7621 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7622 if (E.isInvalid())
7623 return nullptr;
7624 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007625 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007626 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007627 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007628 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7629}
7630
7631template <typename Derived>
7632OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007633TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007634 ExprResult E;
7635 if (auto *Num = C->getNumForLoops()) {
7636 E = getDerived().TransformExpr(Num);
7637 if (E.isInvalid())
7638 return nullptr;
7639 }
7640 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7641 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007642}
7643
7644template <typename Derived>
7645OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007646TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7647 // No need to rebuild this clause, no template-dependent parameters.
7648 return C;
7649}
7650
7651template <typename Derived>
7652OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007653TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7654 // No need to rebuild this clause, no template-dependent parameters.
7655 return C;
7656}
7657
7658template <typename Derived>
7659OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007660TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7661 // No need to rebuild this clause, no template-dependent parameters.
7662 return C;
7663}
7664
7665template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007666OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7667 // No need to rebuild this clause, no template-dependent parameters.
7668 return C;
7669}
7670
7671template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007672OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7673 // No need to rebuild this clause, no template-dependent parameters.
7674 return C;
7675}
7676
7677template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007678OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007679TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7680 // No need to rebuild this clause, no template-dependent parameters.
7681 return C;
7682}
7683
7684template <typename Derived>
7685OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007686TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7687 // No need to rebuild this clause, no template-dependent parameters.
7688 return C;
7689}
7690
7691template <typename Derived>
7692OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007693TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7694 // No need to rebuild this clause, no template-dependent parameters.
7695 return C;
7696}
7697
7698template <typename Derived>
7699OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007700TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7701 // No need to rebuild this clause, no template-dependent parameters.
7702 return C;
7703}
7704
7705template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007706OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7707 // No need to rebuild this clause, no template-dependent parameters.
7708 return C;
7709}
7710
7711template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007712OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007713TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7714 // No need to rebuild this clause, no template-dependent parameters.
7715 return C;
7716}
7717
7718template <typename Derived>
7719OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007720TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007721 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007722 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007723 for (auto *VE : C->varlists()) {
7724 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007725 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007726 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007727 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007728 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007729 return getDerived().RebuildOMPPrivateClause(
7730 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007731}
7732
Alexander Musman64d33f12014-06-04 07:53:32 +00007733template <typename Derived>
7734OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7735 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007736 llvm::SmallVector<Expr *, 16> Vars;
7737 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007738 for (auto *VE : C->varlists()) {
7739 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007740 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007741 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007742 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007743 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007744 return getDerived().RebuildOMPFirstprivateClause(
7745 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007746}
7747
Alexander Musman64d33f12014-06-04 07:53:32 +00007748template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007749OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007750TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7751 llvm::SmallVector<Expr *, 16> Vars;
7752 Vars.reserve(C->varlist_size());
7753 for (auto *VE : C->varlists()) {
7754 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7755 if (EVar.isInvalid())
7756 return nullptr;
7757 Vars.push_back(EVar.get());
7758 }
7759 return getDerived().RebuildOMPLastprivateClause(
7760 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7761}
7762
7763template <typename Derived>
7764OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007765TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7766 llvm::SmallVector<Expr *, 16> Vars;
7767 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007768 for (auto *VE : C->varlists()) {
7769 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007770 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007771 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007772 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007773 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007774 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7775 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007776}
7777
Alexander Musman64d33f12014-06-04 07:53:32 +00007778template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007779OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007780TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7781 llvm::SmallVector<Expr *, 16> Vars;
7782 Vars.reserve(C->varlist_size());
7783 for (auto *VE : C->varlists()) {
7784 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7785 if (EVar.isInvalid())
7786 return nullptr;
7787 Vars.push_back(EVar.get());
7788 }
7789 CXXScopeSpec ReductionIdScopeSpec;
7790 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7791
7792 DeclarationNameInfo NameInfo = C->getNameInfo();
7793 if (NameInfo.getName()) {
7794 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7795 if (!NameInfo.getName())
7796 return nullptr;
7797 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007798 // Build a list of all UDR decls with the same names ranged by the Scopes.
7799 // The Scope boundary is a duplication of the previous decl.
7800 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7801 for (auto *E : C->reduction_ops()) {
7802 // Transform all the decls.
7803 if (E) {
7804 auto *ULE = cast<UnresolvedLookupExpr>(E);
7805 UnresolvedSet<8> Decls;
7806 for (auto *D : ULE->decls()) {
7807 NamedDecl *InstD =
7808 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7809 Decls.addDecl(InstD, InstD->getAccess());
7810 }
7811 UnresolvedReductions.push_back(
7812 UnresolvedLookupExpr::Create(
7813 SemaRef.Context, /*NamingClass=*/nullptr,
7814 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7815 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7816 Decls.begin(), Decls.end()));
7817 } else
7818 UnresolvedReductions.push_back(nullptr);
7819 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007820 return getDerived().RebuildOMPReductionClause(
7821 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007822 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007823}
7824
7825template <typename Derived>
7826OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007827TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7828 llvm::SmallVector<Expr *, 16> Vars;
7829 Vars.reserve(C->varlist_size());
7830 for (auto *VE : C->varlists()) {
7831 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7832 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007833 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007834 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007835 }
7836 ExprResult Step = getDerived().TransformExpr(C->getStep());
7837 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007838 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007839 return getDerived().RebuildOMPLinearClause(
7840 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7841 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007842}
7843
Alexander Musman64d33f12014-06-04 07:53:32 +00007844template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007845OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007846TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7847 llvm::SmallVector<Expr *, 16> Vars;
7848 Vars.reserve(C->varlist_size());
7849 for (auto *VE : C->varlists()) {
7850 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7851 if (EVar.isInvalid())
7852 return nullptr;
7853 Vars.push_back(EVar.get());
7854 }
7855 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7856 if (Alignment.isInvalid())
7857 return nullptr;
7858 return getDerived().RebuildOMPAlignedClause(
7859 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7860 C->getColonLoc(), C->getLocEnd());
7861}
7862
Alexander Musman64d33f12014-06-04 07:53:32 +00007863template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007864OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007865TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7866 llvm::SmallVector<Expr *, 16> Vars;
7867 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007868 for (auto *VE : C->varlists()) {
7869 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007870 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007871 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007872 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007873 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007874 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7875 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007876}
7877
Alexey Bataevbae9a792014-06-27 10:37:06 +00007878template <typename Derived>
7879OMPClause *
7880TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7881 llvm::SmallVector<Expr *, 16> Vars;
7882 Vars.reserve(C->varlist_size());
7883 for (auto *VE : C->varlists()) {
7884 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7885 if (EVar.isInvalid())
7886 return nullptr;
7887 Vars.push_back(EVar.get());
7888 }
7889 return getDerived().RebuildOMPCopyprivateClause(
7890 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7891}
7892
Alexey Bataev6125da92014-07-21 11:26:11 +00007893template <typename Derived>
7894OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7895 llvm::SmallVector<Expr *, 16> Vars;
7896 Vars.reserve(C->varlist_size());
7897 for (auto *VE : C->varlists()) {
7898 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7899 if (EVar.isInvalid())
7900 return nullptr;
7901 Vars.push_back(EVar.get());
7902 }
7903 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7904 C->getLParenLoc(), C->getLocEnd());
7905}
7906
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007907template <typename Derived>
7908OMPClause *
7909TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7910 llvm::SmallVector<Expr *, 16> Vars;
7911 Vars.reserve(C->varlist_size());
7912 for (auto *VE : C->varlists()) {
7913 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7914 if (EVar.isInvalid())
7915 return nullptr;
7916 Vars.push_back(EVar.get());
7917 }
7918 return getDerived().RebuildOMPDependClause(
7919 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7920 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7921}
7922
Michael Wonge710d542015-08-07 16:16:36 +00007923template <typename Derived>
7924OMPClause *
7925TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7926 ExprResult E = getDerived().TransformExpr(C->getDevice());
7927 if (E.isInvalid())
7928 return nullptr;
7929 return getDerived().RebuildOMPDeviceClause(
7930 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7931}
7932
Kelvin Li0bff7af2015-11-23 05:32:03 +00007933template <typename Derived>
7934OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7935 llvm::SmallVector<Expr *, 16> Vars;
7936 Vars.reserve(C->varlist_size());
7937 for (auto *VE : C->varlists()) {
7938 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7939 if (EVar.isInvalid())
7940 return nullptr;
7941 Vars.push_back(EVar.get());
7942 }
7943 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007944 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7945 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7946 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007947}
7948
Kelvin Li099bb8c2015-11-24 20:50:12 +00007949template <typename Derived>
7950OMPClause *
7951TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7952 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7953 if (E.isInvalid())
7954 return nullptr;
7955 return getDerived().RebuildOMPNumTeamsClause(
7956 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7957}
7958
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007959template <typename Derived>
7960OMPClause *
7961TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7962 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7963 if (E.isInvalid())
7964 return nullptr;
7965 return getDerived().RebuildOMPThreadLimitClause(
7966 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7967}
7968
Alexey Bataeva0569352015-12-01 10:17:31 +00007969template <typename Derived>
7970OMPClause *
7971TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7972 ExprResult E = getDerived().TransformExpr(C->getPriority());
7973 if (E.isInvalid())
7974 return nullptr;
7975 return getDerived().RebuildOMPPriorityClause(
7976 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7977}
7978
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007979template <typename Derived>
7980OMPClause *
7981TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7982 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7983 if (E.isInvalid())
7984 return nullptr;
7985 return getDerived().RebuildOMPGrainsizeClause(
7986 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7987}
7988
Alexey Bataev382967a2015-12-08 12:06:20 +00007989template <typename Derived>
7990OMPClause *
7991TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7992 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7993 if (E.isInvalid())
7994 return nullptr;
7995 return getDerived().RebuildOMPNumTasksClause(
7996 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7997}
7998
Alexey Bataev28c75412015-12-15 08:19:24 +00007999template <typename Derived>
8000OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8001 ExprResult E = getDerived().TransformExpr(C->getHint());
8002 if (E.isInvalid())
8003 return nullptr;
8004 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8005 C->getLParenLoc(), C->getLocEnd());
8006}
8007
Carlo Bertollib4adf552016-01-15 18:50:31 +00008008template <typename Derived>
8009OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8010 OMPDistScheduleClause *C) {
8011 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8012 if (E.isInvalid())
8013 return nullptr;
8014 return getDerived().RebuildOMPDistScheduleClause(
8015 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8016 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8017}
8018
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008019template <typename Derived>
8020OMPClause *
8021TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8022 return C;
8023}
8024
Samuel Antao661c0902016-05-26 17:39:58 +00008025template <typename Derived>
8026OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8027 llvm::SmallVector<Expr *, 16> Vars;
8028 Vars.reserve(C->varlist_size());
8029 for (auto *VE : C->varlists()) {
8030 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8031 if (EVar.isInvalid())
8032 return 0;
8033 Vars.push_back(EVar.get());
8034 }
8035 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8036 C->getLParenLoc(), C->getLocEnd());
8037}
8038
Samuel Antaoec172c62016-05-26 17:49:04 +00008039template <typename Derived>
8040OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8041 llvm::SmallVector<Expr *, 16> Vars;
8042 Vars.reserve(C->varlist_size());
8043 for (auto *VE : C->varlists()) {
8044 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8045 if (EVar.isInvalid())
8046 return 0;
8047 Vars.push_back(EVar.get());
8048 }
8049 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8050 C->getLParenLoc(), C->getLocEnd());
8051}
8052
Douglas Gregorebe10102009-08-20 07:17:43 +00008053//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008054// Expression transformation
8055//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008058TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008059 if (!E->isTypeDependent())
8060 return E;
8061
8062 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8063 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008064}
Mike Stump11289f42009-09-09 15:08:12 +00008065
8066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008068TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008069 NestedNameSpecifierLoc QualifierLoc;
8070 if (E->getQualifierLoc()) {
8071 QualifierLoc
8072 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8073 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008074 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008075 }
John McCallce546572009-12-08 09:08:17 +00008076
8077 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008078 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8079 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008082
John McCall815039a2010-08-17 21:27:17 +00008083 DeclarationNameInfo NameInfo = E->getNameInfo();
8084 if (NameInfo.getName()) {
8085 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8086 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008087 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008088 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008089
8090 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008091 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008092 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008093 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008094 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008095
8096 // Mark it referenced in the new context regardless.
8097 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008098 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008099
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008100 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008101 }
John McCallce546572009-12-08 09:08:17 +00008102
Craig Topperc3ec1492014-05-26 06:22:03 +00008103 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008104 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008105 TemplateArgs = &TransArgs;
8106 TransArgs.setLAngleLoc(E->getLAngleLoc());
8107 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008108 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8109 E->getNumTemplateArgs(),
8110 TransArgs))
8111 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008112 }
8113
Chad Rosier1dcde962012-08-08 18:46:20 +00008114 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008115 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008116}
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregora16548e2009-08-11 05:31:07 +00008118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008120TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008121 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008122}
Mike Stump11289f42009-09-09 15:08:12 +00008123
Douglas Gregora16548e2009-08-11 05:31:07 +00008124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008126TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008127 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008128}
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregora16548e2009-08-11 05:31:07 +00008130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008132TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008133 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008134}
Mike Stump11289f42009-09-09 15:08:12 +00008135
Douglas Gregora16548e2009-08-11 05:31:07 +00008136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008137ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008138TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008139 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008140}
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregora16548e2009-08-11 05:31:07 +00008142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008144TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008145 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008146}
8147
8148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008149ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008150TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008151 if (FunctionDecl *FD = E->getDirectCallee())
8152 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008153 return SemaRef.MaybeBindToTemporary(E);
8154}
8155
8156template<typename Derived>
8157ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008158TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8159 ExprResult ControllingExpr =
8160 getDerived().TransformExpr(E->getControllingExpr());
8161 if (ControllingExpr.isInvalid())
8162 return ExprError();
8163
Chris Lattner01cf8db2011-07-20 06:58:45 +00008164 SmallVector<Expr *, 4> AssocExprs;
8165 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008166 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8167 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8168 if (TS) {
8169 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8170 if (!AssocType)
8171 return ExprError();
8172 AssocTypes.push_back(AssocType);
8173 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008174 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008175 }
8176
8177 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8178 if (AssocExpr.isInvalid())
8179 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008180 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008181 }
8182
8183 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8184 E->getDefaultLoc(),
8185 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008186 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008187 AssocTypes,
8188 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008189}
8190
8191template<typename Derived>
8192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008193TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008194 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008197
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008199 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008200
John McCallb268a282010-08-23 23:25:46 +00008201 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008202 E->getRParen());
8203}
8204
Richard Smithdb2630f2012-10-21 03:28:35 +00008205/// \brief The operand of a unary address-of operator has special rules: it's
8206/// allowed to refer to a non-static member of a class even if there's no 'this'
8207/// object available.
8208template<typename Derived>
8209ExprResult
8210TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8211 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008212 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008213 else
8214 return getDerived().TransformExpr(E);
8215}
8216
Mike Stump11289f42009-09-09 15:08:12 +00008217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008219TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008220 ExprResult SubExpr;
8221 if (E->getOpcode() == UO_AddrOf)
8222 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8223 else
8224 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008229 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008230
Douglas Gregora16548e2009-08-11 05:31:07 +00008231 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8232 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008233 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008234}
Mike Stump11289f42009-09-09 15:08:12 +00008235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008237ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008238TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8239 // Transform the type.
8240 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8241 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008243
Douglas Gregor882211c2010-04-28 22:16:22 +00008244 // Transform all of the components into components similar to what the
8245 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008246 // FIXME: It would be slightly more efficient in the non-dependent case to
8247 // just map FieldDecls, rather than requiring the rebuilder to look for
8248 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008249 // template code that we don't care.
8250 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008251 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008252 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008253 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008254 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008255 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008256 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008257 Comp.LocStart = ON.getSourceRange().getBegin();
8258 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008259 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008260 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008261 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008262 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008263 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008264 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008265
Douglas Gregor882211c2010-04-28 22:16:22 +00008266 ExprChanged = ExprChanged || Index.get() != FromIndex;
8267 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008268 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008269 break;
8270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008271
James Y Knight7281c352015-12-29 22:31:18 +00008272 case OffsetOfNode::Field:
8273 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008274 Comp.isBrackets = false;
8275 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008276 if (!Comp.U.IdentInfo)
8277 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008278
Douglas Gregor882211c2010-04-28 22:16:22 +00008279 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008280
James Y Knight7281c352015-12-29 22:31:18 +00008281 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008282 // Will be recomputed during the rebuild.
8283 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008285
Douglas Gregor882211c2010-04-28 22:16:22 +00008286 Components.push_back(Comp);
8287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008288
Douglas Gregor882211c2010-04-28 22:16:22 +00008289 // If nothing changed, retain the existing expression.
8290 if (!getDerived().AlwaysRebuild() &&
8291 Type == E->getTypeSourceInfo() &&
8292 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008293 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008294
Douglas Gregor882211c2010-04-28 22:16:22 +00008295 // Build a new offsetof expression.
8296 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008297 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008298}
8299
8300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008301ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008302TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008303 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008304 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008305 return E;
John McCall8d69a212010-11-15 23:31:06 +00008306}
8307
8308template<typename Derived>
8309ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008310TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8311 return E;
8312}
8313
8314template<typename Derived>
8315ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008316TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008317 // Rebuild the syntactic form. The original syntactic form has
8318 // opaque-value expressions in it, so strip those away and rebuild
8319 // the result. This is a really awful way of doing this, but the
8320 // better solution (rebuilding the semantic expressions and
8321 // rebinding OVEs as necessary) doesn't work; we'd need
8322 // TreeTransform to not strip away implicit conversions.
8323 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8324 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008325 if (result.isInvalid()) return ExprError();
8326
8327 // If that gives us a pseudo-object result back, the pseudo-object
8328 // expression must have been an lvalue-to-rvalue conversion which we
8329 // should reapply.
8330 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008331 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008332
8333 return result;
8334}
8335
8336template<typename Derived>
8337ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008338TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8339 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008340 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008341 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008342
John McCallbcd03502009-12-07 02:54:59 +00008343 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008344 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008346
John McCall4c98fd82009-11-04 07:28:41 +00008347 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008348 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008349
Peter Collingbournee190dee2011-03-11 19:24:49 +00008350 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8351 E->getKind(),
8352 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008353 }
Mike Stump11289f42009-09-09 15:08:12 +00008354
Eli Friedmane4f22df2012-02-29 04:03:55 +00008355 // C++0x [expr.sizeof]p1:
8356 // The operand is either an expression, which is an unevaluated operand
8357 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008358 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8359 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008360
Reid Kleckner32506ed2014-06-12 23:03:48 +00008361 // Try to recover if we have something like sizeof(T::X) where X is a type.
8362 // Notably, there must be *exactly* one set of parens if X is a type.
8363 TypeSourceInfo *RecoveryTSI = nullptr;
8364 ExprResult SubExpr;
8365 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8366 if (auto *DRE =
8367 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8368 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8369 PE, DRE, false, &RecoveryTSI);
8370 else
8371 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8372
8373 if (RecoveryTSI) {
8374 return getDerived().RebuildUnaryExprOrTypeTrait(
8375 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8376 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008378
Eli Friedmane4f22df2012-02-29 04:03:55 +00008379 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008380 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008381
Peter Collingbournee190dee2011-03-11 19:24:49 +00008382 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8383 E->getOperatorLoc(),
8384 E->getKind(),
8385 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008386}
Mike Stump11289f42009-09-09 15:08:12 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008390TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008391 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008394
John McCalldadc5752010-08-24 06:29:42 +00008395 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008396 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008398
8399
Douglas Gregora16548e2009-08-11 05:31:07 +00008400 if (!getDerived().AlwaysRebuild() &&
8401 LHS.get() == E->getLHS() &&
8402 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008403 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008404
John McCallb268a282010-08-23 23:25:46 +00008405 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008406 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008407 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 E->getRBracketLoc());
8409}
Mike Stump11289f42009-09-09 15:08:12 +00008410
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008411template <typename Derived>
8412ExprResult
8413TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8414 ExprResult Base = getDerived().TransformExpr(E->getBase());
8415 if (Base.isInvalid())
8416 return ExprError();
8417
8418 ExprResult LowerBound;
8419 if (E->getLowerBound()) {
8420 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8421 if (LowerBound.isInvalid())
8422 return ExprError();
8423 }
8424
8425 ExprResult Length;
8426 if (E->getLength()) {
8427 Length = getDerived().TransformExpr(E->getLength());
8428 if (Length.isInvalid())
8429 return ExprError();
8430 }
8431
8432 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8433 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8434 return E;
8435
8436 return getDerived().RebuildOMPArraySectionExpr(
8437 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8438 Length.get(), E->getRBracketLoc());
8439}
8440
Mike Stump11289f42009-09-09 15:08:12 +00008441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008443TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008444 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008445 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008446 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008447 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008448
8449 // Transform arguments.
8450 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008451 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008452 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008453 &ArgChanged))
8454 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008455
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 if (!getDerived().AlwaysRebuild() &&
8457 Callee.get() == E->getCallee() &&
8458 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008459 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008460
Douglas Gregora16548e2009-08-11 05:31:07 +00008461 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008462 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008463 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008464 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008465 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008466 E->getRParenLoc());
8467}
Mike Stump11289f42009-09-09 15:08:12 +00008468
8469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008471TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008472 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008473 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008475
Douglas Gregorea972d32011-02-28 21:54:11 +00008476 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008477 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008478 QualifierLoc
8479 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008480
Douglas Gregorea972d32011-02-28 21:54:11 +00008481 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008482 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008483 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008484 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008485
Eli Friedman2cfcef62009-12-04 06:40:45 +00008486 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008487 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8488 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008489 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008491
John McCall16df1e52010-03-30 21:47:33 +00008492 NamedDecl *FoundDecl = E->getFoundDecl();
8493 if (FoundDecl == E->getMemberDecl()) {
8494 FoundDecl = Member;
8495 } else {
8496 FoundDecl = cast_or_null<NamedDecl>(
8497 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8498 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008499 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008500 }
8501
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 if (!getDerived().AlwaysRebuild() &&
8503 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008504 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008505 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008506 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008507 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008508
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008509 // Mark it referenced in the new context regardless.
8510 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008511 SemaRef.MarkMemberReferenced(E);
8512
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008513 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008514 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008515
John McCall6b51f282009-11-23 01:53:49 +00008516 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008517 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008518 TransArgs.setLAngleLoc(E->getLAngleLoc());
8519 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008520 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8521 E->getNumTemplateArgs(),
8522 TransArgs))
8523 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008527 SourceLocation FakeOperatorLoc =
8528 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008529
John McCall38836f02010-01-15 08:34:02 +00008530 // FIXME: to do this check properly, we will need to preserve the
8531 // first-qualifier-in-scope here, just in case we had a dependent
8532 // base (and therefore couldn't do the check) and a
8533 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008534 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008535
John McCallb268a282010-08-23 23:25:46 +00008536 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008537 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008538 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008539 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008540 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008541 Member,
John McCall16df1e52010-03-30 21:47:33 +00008542 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008543 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008544 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008545 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008546}
Mike Stump11289f42009-09-09 15:08:12 +00008547
Douglas Gregora16548e2009-08-11 05:31:07 +00008548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008550TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008551 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008552 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008554
John McCalldadc5752010-08-24 06:29:42 +00008555 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008556 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008558
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 if (!getDerived().AlwaysRebuild() &&
8560 LHS.get() == E->getLHS() &&
8561 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008562 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008563
Lang Hames5de91cc2012-10-02 04:45:10 +00008564 Sema::FPContractStateRAII FPContractState(getSema());
8565 getSema().FPFeatures.fp_contract = E->isFPContractable();
8566
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008568 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008569}
8570
Mike Stump11289f42009-09-09 15:08:12 +00008571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008572ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008573TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008574 CompoundAssignOperator *E) {
8575 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008576}
Mike Stump11289f42009-09-09 15:08:12 +00008577
Douglas Gregora16548e2009-08-11 05:31:07 +00008578template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008579ExprResult TreeTransform<Derived>::
8580TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8581 // Just rebuild the common and RHS expressions and see whether we
8582 // get any changes.
8583
8584 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8585 if (commonExpr.isInvalid())
8586 return ExprError();
8587
8588 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8589 if (rhs.isInvalid())
8590 return ExprError();
8591
8592 if (!getDerived().AlwaysRebuild() &&
8593 commonExpr.get() == e->getCommon() &&
8594 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008595 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008596
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008597 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008598 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008599 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008600 e->getColonLoc(),
8601 rhs.get());
8602}
8603
8604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008606TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008607 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008608 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008610
John McCalldadc5752010-08-24 06:29:42 +00008611 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008612 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008614
John McCalldadc5752010-08-24 06:29:42 +00008615 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008616 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008618
Douglas Gregora16548e2009-08-11 05:31:07 +00008619 if (!getDerived().AlwaysRebuild() &&
8620 Cond.get() == E->getCond() &&
8621 LHS.get() == E->getLHS() &&
8622 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008623 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008624
John McCallb268a282010-08-23 23:25:46 +00008625 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008626 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008627 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008628 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008629 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008630}
Mike Stump11289f42009-09-09 15:08:12 +00008631
8632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008633ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008634TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008635 // Implicit casts are eliminated during transformation, since they
8636 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008637 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008638}
Mike Stump11289f42009-09-09 15:08:12 +00008639
Douglas Gregora16548e2009-08-11 05:31:07 +00008640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008642TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008643 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8644 if (!Type)
8645 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008646
John McCalldadc5752010-08-24 06:29:42 +00008647 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008648 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008651
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008653 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008656
John McCall97513962010-01-15 18:39:57 +00008657 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008658 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008660 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008661}
Mike Stump11289f42009-09-09 15:08:12 +00008662
Douglas Gregora16548e2009-08-11 05:31:07 +00008663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008666 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8667 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8668 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008670
John McCalldadc5752010-08-24 06:29:42 +00008671 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008676 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008678 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008679
John McCall5d7aa7f2010-01-19 22:33:45 +00008680 // Note: the expression type doesn't necessarily match the
8681 // type-as-written, but that's okay, because it should always be
8682 // derivable from the initializer.
8683
John McCalle15bbff2010-01-18 19:35:47 +00008684 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008685 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008686 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008687}
Mike Stump11289f42009-09-09 15:08:12 +00008688
Douglas Gregora16548e2009-08-11 05:31:07 +00008689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008691TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008692 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008693 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008695
Douglas Gregora16548e2009-08-11 05:31:07 +00008696 if (!getDerived().AlwaysRebuild() &&
8697 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008698 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008699
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008701 SourceLocation FakeOperatorLoc =
8702 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008703 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008704 E->getAccessorLoc(),
8705 E->getAccessor());
8706}
Mike Stump11289f42009-09-09 15:08:12 +00008707
Douglas Gregora16548e2009-08-11 05:31:07 +00008708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008709ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008710TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008711 if (InitListExpr *Syntactic = E->getSyntacticForm())
8712 E = Syntactic;
8713
Douglas Gregora16548e2009-08-11 05:31:07 +00008714 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008715
Benjamin Kramerf0623432012-08-23 22:51:59 +00008716 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008717 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008718 Inits, &InitChanged))
8719 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008720
Richard Smith520449d2015-02-05 06:15:50 +00008721 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8722 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8723 // in some cases. We can't reuse it in general, because the syntactic and
8724 // semantic forms are linked, and we can't know that semantic form will
8725 // match even if the syntactic form does.
8726 }
Mike Stump11289f42009-09-09 15:08:12 +00008727
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008728 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008729 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008730}
Mike Stump11289f42009-09-09 15:08:12 +00008731
Douglas Gregora16548e2009-08-11 05:31:07 +00008732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008734TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008735 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008736
Douglas Gregorebe10102009-08-20 07:17:43 +00008737 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008738 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008739 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008741
Douglas Gregorebe10102009-08-20 07:17:43 +00008742 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008743 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008744 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008745 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8746 if (D.isFieldDesignator()) {
8747 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8748 D.getDotLoc(),
8749 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008750 continue;
8751 }
Mike Stump11289f42009-09-09 15:08:12 +00008752
David Majnemerf7e36092016-06-23 00:15:04 +00008753 if (D.isArrayDesignator()) {
8754 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008755 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008757
David Majnemerf7e36092016-06-23 00:15:04 +00008758 Desig.AddDesignator(
8759 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008760
David Majnemerf7e36092016-06-23 00:15:04 +00008761 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008762 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008763 continue;
8764 }
Mike Stump11289f42009-09-09 15:08:12 +00008765
David Majnemerf7e36092016-06-23 00:15:04 +00008766 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008767 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008768 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008771
David Majnemerf7e36092016-06-23 00:15:04 +00008772 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008775
8776 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008777 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008778 D.getLBracketLoc(),
8779 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008780
David Majnemerf7e36092016-06-23 00:15:04 +00008781 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8782 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008783
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008784 ArrayExprs.push_back(Start.get());
8785 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008786 }
Mike Stump11289f42009-09-09 15:08:12 +00008787
Douglas Gregora16548e2009-08-11 05:31:07 +00008788 if (!getDerived().AlwaysRebuild() &&
8789 Init.get() == E->getInit() &&
8790 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008791 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008792
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008793 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008795 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008796}
Mike Stump11289f42009-09-09 15:08:12 +00008797
Yunzhong Gaocb779302015-06-10 00:27:52 +00008798// Seems that if TransformInitListExpr() only works on the syntactic form of an
8799// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8800template<typename Derived>
8801ExprResult
8802TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8803 DesignatedInitUpdateExpr *E) {
8804 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8805 "initializer");
8806 return ExprError();
8807}
8808
8809template<typename Derived>
8810ExprResult
8811TreeTransform<Derived>::TransformNoInitExpr(
8812 NoInitExpr *E) {
8813 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8814 return ExprError();
8815}
8816
Douglas Gregora16548e2009-08-11 05:31:07 +00008817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008818ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008819TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008820 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008821 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008822
Douglas Gregor3da3c062009-10-28 00:29:27 +00008823 // FIXME: Will we ever have proper type location here? Will we actually
8824 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008825 QualType T = getDerived().TransformType(E->getType());
8826 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008828
Douglas Gregora16548e2009-08-11 05:31:07 +00008829 if (!getDerived().AlwaysRebuild() &&
8830 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008831 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833 return getDerived().RebuildImplicitValueInitExpr(T);
8834}
Mike Stump11289f42009-09-09 15:08:12 +00008835
Douglas Gregora16548e2009-08-11 05:31:07 +00008836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008838TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008839 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8840 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008842
John McCalldadc5752010-08-24 06:29:42 +00008843 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008846
Douglas Gregora16548e2009-08-11 05:31:07 +00008847 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008848 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008850 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008851
John McCallb268a282010-08-23 23:25:46 +00008852 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008853 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008854}
8855
8856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008858TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008859 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008860 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008861 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8862 &ArgumentChanged))
8863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008864
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008866 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008867 E->getRParenLoc());
8868}
Mike Stump11289f42009-09-09 15:08:12 +00008869
Douglas Gregora16548e2009-08-11 05:31:07 +00008870/// \brief Transform an address-of-label expression.
8871///
8872/// By default, the transformation of an address-of-label expression always
8873/// rebuilds the expression, so that the label identifier can be resolved to
8874/// the corresponding label statement by semantic analysis.
8875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008877TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008878 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8879 E->getLabel());
8880 if (!LD)
8881 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008882
Douglas Gregora16548e2009-08-11 05:31:07 +00008883 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008884 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008885}
Mike Stump11289f42009-09-09 15:08:12 +00008886
8887template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008889TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008890 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008891 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008892 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008893 if (SubStmt.isInvalid()) {
8894 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008895 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008896 }
Mike Stump11289f42009-09-09 15:08:12 +00008897
Douglas Gregora16548e2009-08-11 05:31:07 +00008898 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008899 SubStmt.get() == E->getSubStmt()) {
8900 // Calling this an 'error' is unintuitive, but it does the right thing.
8901 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008902 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008903 }
Mike Stump11289f42009-09-09 15:08:12 +00008904
8905 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008906 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 E->getRParenLoc());
8908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
Douglas Gregora16548e2009-08-11 05:31:07 +00008910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008912TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008913 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008914 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008916
John McCalldadc5752010-08-24 06:29:42 +00008917 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008920
John McCalldadc5752010-08-24 06:29:42 +00008921 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008922 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008924
Douglas Gregora16548e2009-08-11 05:31:07 +00008925 if (!getDerived().AlwaysRebuild() &&
8926 Cond.get() == E->getCond() &&
8927 LHS.get() == E->getLHS() &&
8928 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008929 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregora16548e2009-08-11 05:31:07 +00008931 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008932 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008933 E->getRParenLoc());
8934}
Mike Stump11289f42009-09-09 15:08:12 +00008935
Douglas Gregora16548e2009-08-11 05:31:07 +00008936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008938TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008939 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008940}
8941
8942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008944TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008945 switch (E->getOperator()) {
8946 case OO_New:
8947 case OO_Delete:
8948 case OO_Array_New:
8949 case OO_Array_Delete:
8950 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008951
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008952 case OO_Call: {
8953 // This is a call to an object's operator().
8954 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8955
8956 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008957 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008958 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008959 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008960
8961 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008962 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8963 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008964
8965 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008966 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008967 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008968 Args))
8969 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008970
John McCallb268a282010-08-23 23:25:46 +00008971 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008972 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008973 E->getLocEnd());
8974 }
8975
8976#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8977 case OO_##Name:
8978#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8979#include "clang/Basic/OperatorKinds.def"
8980 case OO_Subscript:
8981 // Handled below.
8982 break;
8983
8984 case OO_Conditional:
8985 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008986
8987 case OO_None:
8988 case NUM_OVERLOADED_OPERATORS:
8989 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008990 }
8991
John McCalldadc5752010-08-24 06:29:42 +00008992 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008993 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008995
Richard Smithdb2630f2012-10-21 03:28:35 +00008996 ExprResult First;
8997 if (E->getOperator() == OO_Amp)
8998 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8999 else
9000 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009001 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009002 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009003
John McCalldadc5752010-08-24 06:29:42 +00009004 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009005 if (E->getNumArgs() == 2) {
9006 Second = getDerived().TransformExpr(E->getArg(1));
9007 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009008 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009009 }
Mike Stump11289f42009-09-09 15:08:12 +00009010
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 if (!getDerived().AlwaysRebuild() &&
9012 Callee.get() == E->getCallee() &&
9013 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009014 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009015 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009016
Lang Hames5de91cc2012-10-02 04:45:10 +00009017 Sema::FPContractStateRAII FPContractState(getSema());
9018 getSema().FPFeatures.fp_contract = E->isFPContractable();
9019
Douglas Gregora16548e2009-08-11 05:31:07 +00009020 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9021 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009022 Callee.get(),
9023 First.get(),
9024 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009025}
Mike Stump11289f42009-09-09 15:08:12 +00009026
Douglas Gregora16548e2009-08-11 05:31:07 +00009027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009028ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009029TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9030 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009031}
Mike Stump11289f42009-09-09 15:08:12 +00009032
Douglas Gregora16548e2009-08-11 05:31:07 +00009033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009034ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009035TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9036 // Transform the callee.
9037 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9038 if (Callee.isInvalid())
9039 return ExprError();
9040
9041 // Transform exec config.
9042 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9043 if (EC.isInvalid())
9044 return ExprError();
9045
9046 // Transform arguments.
9047 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009048 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009049 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009050 &ArgChanged))
9051 return ExprError();
9052
9053 if (!getDerived().AlwaysRebuild() &&
9054 Callee.get() == E->getCallee() &&
9055 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009056 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009057
9058 // FIXME: Wrong source location information for the '('.
9059 SourceLocation FakeLParenLoc
9060 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9061 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009062 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009063 E->getRParenLoc(), EC.get());
9064}
9065
9066template<typename Derived>
9067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009068TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009069 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9070 if (!Type)
9071 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009072
John McCalldadc5752010-08-24 06:29:42 +00009073 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009074 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009075 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009077
Douglas Gregora16548e2009-08-11 05:31:07 +00009078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009079 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009080 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009081 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009082 return getDerived().RebuildCXXNamedCastExpr(
9083 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9084 Type, E->getAngleBrackets().getEnd(),
9085 // FIXME. this should be '(' location
9086 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009087}
Mike Stump11289f42009-09-09 15:08:12 +00009088
Douglas Gregora16548e2009-08-11 05:31:07 +00009089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9092 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009093}
Mike Stump11289f42009-09-09 15:08:12 +00009094
9095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009097TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9098 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009099}
9100
Douglas Gregora16548e2009-08-11 05:31:07 +00009101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009102ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009103TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009104 CXXReinterpretCastExpr *E) {
9105 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009106}
Mike Stump11289f42009-09-09 15:08:12 +00009107
Douglas Gregora16548e2009-08-11 05:31:07 +00009108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009110TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9111 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009112}
Mike Stump11289f42009-09-09 15:08:12 +00009113
Douglas Gregora16548e2009-08-11 05:31:07 +00009114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009115ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009116TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009117 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009118 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9119 if (!Type)
9120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009121
John McCalldadc5752010-08-24 06:29:42 +00009122 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009123 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (SubExpr.isInvalid())
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 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009128 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009129 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009130 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009131
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009132 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009133 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009134 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009135 E->getRParenLoc());
9136}
Mike Stump11289f42009-09-09 15:08:12 +00009137
Douglas Gregora16548e2009-08-11 05:31:07 +00009138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009140TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009142 TypeSourceInfo *TInfo
9143 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9144 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009146
Douglas Gregora16548e2009-08-11 05:31:07 +00009147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009148 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009149 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009150
Douglas Gregor9da64192010-04-26 22:37:10 +00009151 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9152 E->getLocStart(),
9153 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009154 E->getLocEnd());
9155 }
Mike Stump11289f42009-09-09 15:08:12 +00009156
Eli Friedman456f0182012-01-20 01:26:23 +00009157 // We don't know whether the subexpression is potentially evaluated until
9158 // after we perform semantic analysis. We speculatively assume it is
9159 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009160 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009161 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9162 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009163
John McCalldadc5752010-08-24 06:29:42 +00009164 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009165 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009167
Douglas Gregora16548e2009-08-11 05:31:07 +00009168 if (!getDerived().AlwaysRebuild() &&
9169 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009170 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009171
Douglas Gregor9da64192010-04-26 22:37:10 +00009172 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9173 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009174 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 E->getLocEnd());
9176}
9177
9178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009179ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009180TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9181 if (E->isTypeOperand()) {
9182 TypeSourceInfo *TInfo
9183 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9184 if (!TInfo)
9185 return ExprError();
9186
9187 if (!getDerived().AlwaysRebuild() &&
9188 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009189 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009190
Douglas Gregor69735112011-03-06 17:40:41 +00009191 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009192 E->getLocStart(),
9193 TInfo,
9194 E->getLocEnd());
9195 }
9196
Francois Pichet9f4f2072010-09-08 12:20:18 +00009197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9198
9199 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9200 if (SubExpr.isInvalid())
9201 return ExprError();
9202
9203 if (!getDerived().AlwaysRebuild() &&
9204 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009205 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009206
9207 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9208 E->getLocStart(),
9209 SubExpr.get(),
9210 E->getLocEnd());
9211}
9212
9213template<typename Derived>
9214ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009215TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009216 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009217}
Mike Stump11289f42009-09-09 15:08:12 +00009218
Douglas Gregora16548e2009-08-11 05:31:07 +00009219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009220ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009221TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009222 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009223 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009224}
Mike Stump11289f42009-09-09 15:08:12 +00009225
Douglas Gregora16548e2009-08-11 05:31:07 +00009226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009228TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009229 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009230
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009231 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9232 // Make sure that we capture 'this'.
9233 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009236
Douglas Gregorb15af892010-01-07 23:12:05 +00009237 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009238}
Mike Stump11289f42009-09-09 15:08:12 +00009239
Douglas Gregora16548e2009-08-11 05:31:07 +00009240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009242TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009243 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009244 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009246
Douglas Gregora16548e2009-08-11 05:31:07 +00009247 if (!getDerived().AlwaysRebuild() &&
9248 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009249 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009250
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009251 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9252 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009253}
Mike Stump11289f42009-09-09 15:08:12 +00009254
Douglas Gregora16548e2009-08-11 05:31:07 +00009255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009258 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009259 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9260 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009261 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009262 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009263
Chandler Carruth794da4c2010-02-08 06:42:49 +00009264 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009265 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009266 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009267
Douglas Gregor033f6752009-12-23 23:03:06 +00009268 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009269}
Mike Stump11289f42009-09-09 15:08:12 +00009270
Douglas Gregora16548e2009-08-11 05:31:07 +00009271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009272ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009273TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9274 FieldDecl *Field
9275 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9276 E->getField()));
9277 if (!Field)
9278 return ExprError();
9279
9280 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009281 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009282
9283 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9284}
9285
9286template<typename Derived>
9287ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009288TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9289 CXXScalarValueInitExpr *E) {
9290 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9291 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009292 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Douglas Gregora16548e2009-08-11 05:31:07 +00009294 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009295 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009296 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009297
Chad Rosier1dcde962012-08-08 18:46:20 +00009298 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009299 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009300 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009301}
Mike Stump11289f42009-09-09 15:08:12 +00009302
Douglas Gregora16548e2009-08-11 05:31:07 +00009303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009305TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009306 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009307 TypeSourceInfo *AllocTypeInfo
9308 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9309 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009311
Douglas Gregora16548e2009-08-11 05:31:07 +00009312 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009313 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009314 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009316
Douglas Gregora16548e2009-08-11 05:31:07 +00009317 // Transform the placement arguments (if any).
9318 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009319 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009320 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009321 E->getNumPlacementArgs(), true,
9322 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009324
Sebastian Redl6047f072012-02-16 12:22:20 +00009325 // Transform the initializer (if any).
9326 Expr *OldInit = E->getInitializer();
9327 ExprResult NewInit;
9328 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009329 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009330 if (NewInit.isInvalid())
9331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009332
Sebastian Redl6047f072012-02-16 12:22:20 +00009333 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009334 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009335 if (E->getOperatorNew()) {
9336 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009337 getDerived().TransformDecl(E->getLocStart(),
9338 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009339 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009340 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009341 }
9342
Craig Topperc3ec1492014-05-26 06:22:03 +00009343 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009344 if (E->getOperatorDelete()) {
9345 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009346 getDerived().TransformDecl(E->getLocStart(),
9347 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009348 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009349 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009350 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009351
Douglas Gregora16548e2009-08-11 05:31:07 +00009352 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009353 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009354 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009355 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009356 OperatorNew == E->getOperatorNew() &&
9357 OperatorDelete == E->getOperatorDelete() &&
9358 !ArgumentChanged) {
9359 // Mark any declarations we need as referenced.
9360 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009361 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009362 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009363 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009364 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009365
Sebastian Redl6047f072012-02-16 12:22:20 +00009366 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009367 QualType ElementType
9368 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9369 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9370 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9371 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009372 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009373 }
9374 }
9375 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009376
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009377 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009378 }
Mike Stump11289f42009-09-09 15:08:12 +00009379
Douglas Gregor0744ef62010-09-07 21:49:58 +00009380 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009381 if (!ArraySize.get()) {
9382 // If no array size was specified, but the new expression was
9383 // instantiated with an array type (e.g., "new T" where T is
9384 // instantiated with "int[4]"), extract the outer bound from the
9385 // array type as our array size. We do this with constant and
9386 // dependently-sized array types.
9387 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9388 if (!ArrayT) {
9389 // Do nothing
9390 } else if (const ConstantArrayType *ConsArrayT
9391 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009392 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9393 SemaRef.Context.getSizeType(),
9394 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009395 AllocType = ConsArrayT->getElementType();
9396 } else if (const DependentSizedArrayType *DepArrayT
9397 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9398 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009399 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009400 AllocType = DepArrayT->getElementType();
9401 }
9402 }
9403 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009404
Douglas Gregora16548e2009-08-11 05:31:07 +00009405 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9406 E->isGlobalNew(),
9407 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009408 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009409 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009410 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009412 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009413 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009414 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009415 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009416}
Mike Stump11289f42009-09-09 15:08:12 +00009417
Douglas Gregora16548e2009-08-11 05:31:07 +00009418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009420TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009421 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009422 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009424
Douglas Gregord2d9da02010-02-26 00:38:10 +00009425 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009426 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009427 if (E->getOperatorDelete()) {
9428 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009429 getDerived().TransformDecl(E->getLocStart(),
9430 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009431 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009432 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009433 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009434
Douglas Gregora16548e2009-08-11 05:31:07 +00009435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009436 Operand.get() == E->getArgument() &&
9437 OperatorDelete == E->getOperatorDelete()) {
9438 // Mark any declarations we need as referenced.
9439 // FIXME: instantiation-specific.
9440 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009441 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009442
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009443 if (!E->getArgument()->isTypeDependent()) {
9444 QualType Destroyed = SemaRef.Context.getBaseElementType(
9445 E->getDestroyedType());
9446 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9447 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009448 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009449 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009450 }
9451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009452
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009453 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009454 }
Mike Stump11289f42009-09-09 15:08:12 +00009455
Douglas Gregora16548e2009-08-11 05:31:07 +00009456 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9457 E->isGlobalDelete(),
9458 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009459 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009460}
Mike Stump11289f42009-09-09 15:08:12 +00009461
Douglas Gregora16548e2009-08-11 05:31:07 +00009462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009463ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009464TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009465 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009466 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009467 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009469
John McCallba7bf592010-08-24 05:47:05 +00009470 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009471 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009472 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009473 E->getOperatorLoc(),
9474 E->isArrow()? tok::arrow : tok::period,
9475 ObjectTypePtr,
9476 MayBePseudoDestructor);
9477 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009478 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009479
John McCallba7bf592010-08-24 05:47:05 +00009480 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009481 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9482 if (QualifierLoc) {
9483 QualifierLoc
9484 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9485 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009486 return ExprError();
9487 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009488 CXXScopeSpec SS;
9489 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009490
Douglas Gregor678f90d2010-02-25 01:56:36 +00009491 PseudoDestructorTypeStorage Destroyed;
9492 if (E->getDestroyedTypeInfo()) {
9493 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009494 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009495 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009496 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009497 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009498 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009499 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009500 // We aren't likely to be able to resolve the identifier down to a type
9501 // now anyway, so just retain the identifier.
9502 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9503 E->getDestroyedTypeLoc());
9504 } else {
9505 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009506 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009507 *E->getDestroyedTypeIdentifier(),
9508 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009509 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009510 SS, ObjectTypePtr,
9511 false);
9512 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009514
Douglas Gregor678f90d2010-02-25 01:56:36 +00009515 Destroyed
9516 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9517 E->getDestroyedTypeLoc());
9518 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009519
Craig Topperc3ec1492014-05-26 06:22:03 +00009520 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009521 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009522 CXXScopeSpec EmptySS;
9523 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009524 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009525 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009526 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009528
John McCallb268a282010-08-23 23:25:46 +00009529 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009530 E->getOperatorLoc(),
9531 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009532 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009533 ScopeTypeInfo,
9534 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009535 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009536 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009537}
Mike Stump11289f42009-09-09 15:08:12 +00009538
Douglas Gregorad8a3362009-09-04 17:36:40 +00009539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009540ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009541TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009542 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009543 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9544 Sema::LookupOrdinaryName);
9545
9546 // Transform all the decls.
9547 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9548 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009549 NamedDecl *InstD = static_cast<NamedDecl*>(
9550 getDerived().TransformDecl(Old->getNameLoc(),
9551 *I));
John McCall84d87672009-12-10 09:41:52 +00009552 if (!InstD) {
9553 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9554 // This can happen because of dependent hiding.
9555 if (isa<UsingShadowDecl>(*I))
9556 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009557 else {
9558 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009559 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009560 }
John McCall84d87672009-12-10 09:41:52 +00009561 }
John McCalle66edc12009-11-24 19:00:30 +00009562
9563 // Expand using declarations.
9564 if (isa<UsingDecl>(InstD)) {
9565 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009566 for (auto *I : UD->shadows())
9567 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009568 continue;
9569 }
9570
9571 R.addDecl(InstD);
9572 }
9573
9574 // Resolve a kind, but don't do any further analysis. If it's
9575 // ambiguous, the callee needs to deal with it.
9576 R.resolveKind();
9577
9578 // Rebuild the nested-name qualifier, if present.
9579 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009580 if (Old->getQualifierLoc()) {
9581 NestedNameSpecifierLoc QualifierLoc
9582 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9583 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009584 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009585
Douglas Gregor0da1d432011-02-28 20:01:57 +00009586 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009587 }
9588
Douglas Gregor9262f472010-04-27 18:19:34 +00009589 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009590 CXXRecordDecl *NamingClass
9591 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9592 Old->getNameLoc(),
9593 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009594 if (!NamingClass) {
9595 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009596 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009598
Douglas Gregorda7be082010-04-27 16:10:10 +00009599 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009600 }
9601
Abramo Bagnara7945c982012-01-27 09:46:47 +00009602 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9603
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009604 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009605 // it's a normal declaration name or member reference.
9606 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9607 NamedDecl *D = R.getAsSingle<NamedDecl>();
9608 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9609 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9610 // give a good diagnostic.
9611 if (D && D->isCXXInstanceMember()) {
9612 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9613 /*TemplateArgs=*/nullptr,
9614 /*Scope=*/nullptr);
9615 }
9616
John McCalle66edc12009-11-24 19:00:30 +00009617 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009618 }
John McCalle66edc12009-11-24 19:00:30 +00009619
9620 // If we have template arguments, rebuild them, then rebuild the
9621 // templateid expression.
9622 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009623 if (Old->hasExplicitTemplateArgs() &&
9624 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009625 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009626 TransArgs)) {
9627 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009628 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009629 }
John McCalle66edc12009-11-24 19:00:30 +00009630
Abramo Bagnara7945c982012-01-27 09:46:47 +00009631 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009632 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009633}
Mike Stump11289f42009-09-09 15:08:12 +00009634
Douglas Gregora16548e2009-08-11 05:31:07 +00009635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009636ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009637TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9638 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009639 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009640 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9641 TypeSourceInfo *From = E->getArg(I);
9642 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009643 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009644 TypeLocBuilder TLB;
9645 TLB.reserve(FromTL.getFullDataSize());
9646 QualType To = getDerived().TransformType(TLB, FromTL);
9647 if (To.isNull())
9648 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009649
Douglas Gregor29c42f22012-02-24 07:38:34 +00009650 if (To == From->getType())
9651 Args.push_back(From);
9652 else {
9653 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9654 ArgChanged = true;
9655 }
9656 continue;
9657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009658
Douglas Gregor29c42f22012-02-24 07:38:34 +00009659 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009660
Douglas Gregor29c42f22012-02-24 07:38:34 +00009661 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009662 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009663 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9664 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9665 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009666
Douglas Gregor29c42f22012-02-24 07:38:34 +00009667 // Determine whether the set of unexpanded parameter packs can and should
9668 // be expanded.
9669 bool Expand = true;
9670 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009671 Optional<unsigned> OrigNumExpansions =
9672 ExpansionTL.getTypePtr()->getNumExpansions();
9673 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009674 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9675 PatternTL.getSourceRange(),
9676 Unexpanded,
9677 Expand, RetainExpansion,
9678 NumExpansions))
9679 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009680
Douglas Gregor29c42f22012-02-24 07:38:34 +00009681 if (!Expand) {
9682 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009683 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009684 // expansion.
9685 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
Douglas Gregor29c42f22012-02-24 07:38:34 +00009687 TypeLocBuilder TLB;
9688 TLB.reserve(From->getTypeLoc().getFullDataSize());
9689
9690 QualType To = getDerived().TransformType(TLB, PatternTL);
9691 if (To.isNull())
9692 return ExprError();
9693
Chad Rosier1dcde962012-08-08 18:46:20 +00009694 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009695 PatternTL.getSourceRange(),
9696 ExpansionTL.getEllipsisLoc(),
9697 NumExpansions);
9698 if (To.isNull())
9699 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Douglas Gregor29c42f22012-02-24 07:38:34 +00009701 PackExpansionTypeLoc ToExpansionTL
9702 = TLB.push<PackExpansionTypeLoc>(To);
9703 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9704 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9705 continue;
9706 }
9707
9708 // Expand the pack expansion by substituting for each argument in the
9709 // pack(s).
9710 for (unsigned I = 0; I != *NumExpansions; ++I) {
9711 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9712 TypeLocBuilder TLB;
9713 TLB.reserve(PatternTL.getFullDataSize());
9714 QualType To = getDerived().TransformType(TLB, PatternTL);
9715 if (To.isNull())
9716 return ExprError();
9717
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009718 if (To->containsUnexpandedParameterPack()) {
9719 To = getDerived().RebuildPackExpansionType(To,
9720 PatternTL.getSourceRange(),
9721 ExpansionTL.getEllipsisLoc(),
9722 NumExpansions);
9723 if (To.isNull())
9724 return ExprError();
9725
9726 PackExpansionTypeLoc ToExpansionTL
9727 = TLB.push<PackExpansionTypeLoc>(To);
9728 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9729 }
9730
Douglas Gregor29c42f22012-02-24 07:38:34 +00009731 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9732 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009733
Douglas Gregor29c42f22012-02-24 07:38:34 +00009734 if (!RetainExpansion)
9735 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009736
Douglas Gregor29c42f22012-02-24 07:38:34 +00009737 // If we're supposed to retain a pack expansion, do so by temporarily
9738 // forgetting the partially-substituted parameter pack.
9739 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9740
9741 TypeLocBuilder TLB;
9742 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009743
Douglas Gregor29c42f22012-02-24 07:38:34 +00009744 QualType To = getDerived().TransformType(TLB, PatternTL);
9745 if (To.isNull())
9746 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009747
9748 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009749 PatternTL.getSourceRange(),
9750 ExpansionTL.getEllipsisLoc(),
9751 NumExpansions);
9752 if (To.isNull())
9753 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009754
Douglas Gregor29c42f22012-02-24 07:38:34 +00009755 PackExpansionTypeLoc ToExpansionTL
9756 = TLB.push<PackExpansionTypeLoc>(To);
9757 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9758 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009760
Douglas Gregor29c42f22012-02-24 07:38:34 +00009761 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009762 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009763
9764 return getDerived().RebuildTypeTrait(E->getTrait(),
9765 E->getLocStart(),
9766 Args,
9767 E->getLocEnd());
9768}
9769
9770template<typename Derived>
9771ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009772TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9773 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9774 if (!T)
9775 return ExprError();
9776
9777 if (!getDerived().AlwaysRebuild() &&
9778 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009779 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009780
9781 ExprResult SubExpr;
9782 {
9783 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9784 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9785 if (SubExpr.isInvalid())
9786 return ExprError();
9787
9788 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009789 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009790 }
9791
9792 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9793 E->getLocStart(),
9794 T,
9795 SubExpr.get(),
9796 E->getLocEnd());
9797}
9798
9799template<typename Derived>
9800ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009801TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9802 ExprResult SubExpr;
9803 {
9804 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9805 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9806 if (SubExpr.isInvalid())
9807 return ExprError();
9808
9809 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009810 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009811 }
9812
9813 return getDerived().RebuildExpressionTrait(
9814 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9815}
9816
Reid Kleckner32506ed2014-06-12 23:03:48 +00009817template <typename Derived>
9818ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9819 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9820 TypeSourceInfo **RecoveryTSI) {
9821 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9822 DRE, AddrTaken, RecoveryTSI);
9823
9824 // Propagate both errors and recovered types, which return ExprEmpty.
9825 if (!NewDRE.isUsable())
9826 return NewDRE;
9827
9828 // We got an expr, wrap it up in parens.
9829 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9830 return PE;
9831 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9832 PE->getRParen());
9833}
9834
9835template <typename Derived>
9836ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9837 DependentScopeDeclRefExpr *E) {
9838 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9839 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009840}
9841
9842template<typename Derived>
9843ExprResult
9844TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9845 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009846 bool IsAddressOfOperand,
9847 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009848 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009849 NestedNameSpecifierLoc QualifierLoc
9850 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9851 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009852 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009853 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009854
John McCall31f82722010-11-12 08:19:04 +00009855 // TODO: If this is a conversion-function-id, verify that the
9856 // destination type name (if present) resolves the same way after
9857 // instantiation as it did in the local scope.
9858
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009859 DeclarationNameInfo NameInfo
9860 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9861 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009863
John McCalle66edc12009-11-24 19:00:30 +00009864 if (!E->hasExplicitTemplateArgs()) {
9865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009866 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009867 // Note: it is sufficient to compare the Name component of NameInfo:
9868 // if name has not changed, DNLoc has not changed either.
9869 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009870 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009871
Reid Kleckner32506ed2014-06-12 23:03:48 +00009872 return getDerived().RebuildDependentScopeDeclRefExpr(
9873 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9874 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009875 }
John McCall6b51f282009-11-23 01:53:49 +00009876
9877 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009878 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9879 E->getNumTemplateArgs(),
9880 TransArgs))
9881 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009882
Reid Kleckner32506ed2014-06-12 23:03:48 +00009883 return getDerived().RebuildDependentScopeDeclRefExpr(
9884 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9885 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009886}
9887
9888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009890TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009891 // CXXConstructExprs other than for list-initialization and
9892 // CXXTemporaryObjectExpr are always implicit, so when we have
9893 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009894 if ((E->getNumArgs() == 1 ||
9895 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009896 (!getDerived().DropCallArgument(E->getArg(0))) &&
9897 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009898 return getDerived().TransformExpr(E->getArg(0));
9899
Douglas Gregora16548e2009-08-11 05:31:07 +00009900 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9901
9902 QualType T = getDerived().TransformType(E->getType());
9903 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009904 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009905
9906 CXXConstructorDecl *Constructor
9907 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009908 getDerived().TransformDecl(E->getLocStart(),
9909 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009910 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009912
Douglas Gregora16548e2009-08-11 05:31:07 +00009913 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009914 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009915 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009916 &ArgumentChanged))
9917 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009918
Douglas Gregora16548e2009-08-11 05:31:07 +00009919 if (!getDerived().AlwaysRebuild() &&
9920 T == E->getType() &&
9921 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009922 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009923 // Mark the constructor as referenced.
9924 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009925 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009926 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009927 }
Mike Stump11289f42009-09-09 15:08:12 +00009928
Douglas Gregordb121ba2009-12-14 16:27:04 +00009929 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +00009930 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00009931 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009932 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009933 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009934 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009935 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009936 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009937 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009938}
Mike Stump11289f42009-09-09 15:08:12 +00009939
Douglas Gregora16548e2009-08-11 05:31:07 +00009940/// \brief Transform a C++ temporary-binding expression.
9941///
Douglas Gregor363b1512009-12-24 18:51:59 +00009942/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9943/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009946TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009947 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009948}
Mike Stump11289f42009-09-09 15:08:12 +00009949
John McCall5d413782010-12-06 08:20:24 +00009950/// \brief Transform a C++ expression that contains cleanups that should
9951/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009952///
John McCall5d413782010-12-06 08:20:24 +00009953/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009954/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009956ExprResult
John McCall5d413782010-12-06 08:20:24 +00009957TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009958 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009959}
Mike Stump11289f42009-09-09 15:08:12 +00009960
Douglas Gregora16548e2009-08-11 05:31:07 +00009961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009962ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009963TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009964 CXXTemporaryObjectExpr *E) {
9965 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9966 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009968
Douglas Gregora16548e2009-08-11 05:31:07 +00009969 CXXConstructorDecl *Constructor
9970 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009971 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009972 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009973 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009975
Douglas Gregora16548e2009-08-11 05:31:07 +00009976 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009977 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009978 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009979 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009980 &ArgumentChanged))
9981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009982
Douglas Gregora16548e2009-08-11 05:31:07 +00009983 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009984 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009985 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009986 !ArgumentChanged) {
9987 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009988 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009989 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009991
Richard Smithd59b8322012-12-19 01:39:02 +00009992 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009993 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9994 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009995 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009996 E->getLocEnd());
9997}
Mike Stump11289f42009-09-09 15:08:12 +00009998
Douglas Gregora16548e2009-08-11 05:31:07 +00009999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010000ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010001TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010002 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010003 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010004 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010005 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10006 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010007 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010008 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010009 CEnd = E->capture_end();
10010 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010011 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010012 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010013 EnterExpressionEvaluationContext EEEC(getSema(),
10014 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010015 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10016 C->getCapturedVar()->getInit(),
10017 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010018
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010019 if (NewExprInitResult.isInvalid())
10020 return ExprError();
10021 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010022
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010023 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010024 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010025 getSema().buildLambdaInitCaptureInitialization(
10026 C->getLocation(), OldVD->getType()->isReferenceType(),
10027 OldVD->getIdentifier(),
10028 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010029 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010030 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10031 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010032 }
10033
Faisal Vali2cba1332013-10-23 06:44:28 +000010034 // Transform the template parameters, and add them to the current
10035 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010036 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010037 E->getTemplateParameterList());
10038
Richard Smith01014ce2014-11-20 23:53:14 +000010039 // Transform the type of the original lambda's call operator.
10040 // The transformation MUST be done in the CurrentInstantiationScope since
10041 // it introduces a mapping of the original to the newly created
10042 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010043 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010044 {
10045 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10046 FunctionProtoTypeLoc OldCallOpFPTL =
10047 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010048
10049 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010050 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010051 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010052 QualType NewCallOpType = TransformFunctionProtoType(
10053 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010054 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10055 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10056 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010057 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010058 if (NewCallOpType.isNull())
10059 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010060 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10061 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010062 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010063
Richard Smithc38498f2015-04-27 21:27:54 +000010064 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10065 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10066 LSI->GLTemplateParameterList = TPL;
10067
Eli Friedmand564afb2012-09-19 01:18:11 +000010068 // Create the local class that will describe the lambda.
10069 CXXRecordDecl *Class
10070 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010071 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010072 /*KnownDependent=*/false,
10073 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010074 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10075
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010076 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010077 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10078 Class, E->getIntroducerRange(), NewCallOpTSI,
10079 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010080 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10081 E->getCallOperator()->isConstexpr());
10082
Faisal Vali2cba1332013-10-23 06:44:28 +000010083 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010084
Faisal Vali2cba1332013-10-23 06:44:28 +000010085 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010086 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010087
Douglas Gregorb4328232012-02-14 00:00:48 +000010088 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010089 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010090 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010091
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010092 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010093 getSema().buildLambdaScope(LSI, NewCallOperator,
10094 E->getIntroducerRange(),
10095 E->getCaptureDefault(),
10096 E->getCaptureDefaultLoc(),
10097 E->hasExplicitParameters(),
10098 E->hasExplicitResultType(),
10099 E->isMutable());
10100
10101 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010102
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010103 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010104 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010105 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010106 CEnd = E->capture_end();
10107 C != CEnd; ++C) {
10108 // When we hit the first implicit capture, tell Sema that we've finished
10109 // the list of explicit captures.
10110 if (!FinishedExplicitCaptures && C->isImplicit()) {
10111 getSema().finishLambdaExplicitCaptures(LSI);
10112 FinishedExplicitCaptures = true;
10113 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010115 // Capturing 'this' is trivial.
10116 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010117 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10118 /*BuildAndDiagnose*/ true, nullptr,
10119 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010120 continue;
10121 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010122 // Captured expression will be recaptured during captured variables
10123 // rebuilding.
10124 if (C->capturesVLAType())
10125 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010126
Richard Smithba71c082013-05-16 06:20:58 +000010127 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010128 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010129 InitCaptureInfoTy InitExprTypePair =
10130 InitCaptureExprsAndTypes[C - E->capture_begin()];
10131 ExprResult Init = InitExprTypePair.first;
10132 QualType InitQualType = InitExprTypePair.second;
10133 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010134 Invalid = true;
10135 continue;
10136 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010137 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010138 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010139 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10140 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010141 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010142 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010143 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010144 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010145 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010146 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010147 continue;
10148 }
10149
10150 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10151
Douglas Gregor3e308b12012-02-14 19:27:52 +000010152 // Determine the capture kind for Sema.
10153 Sema::TryCaptureKind Kind
10154 = C->isImplicit()? Sema::TryCapture_Implicit
10155 : C->getCaptureKind() == LCK_ByCopy
10156 ? Sema::TryCapture_ExplicitByVal
10157 : Sema::TryCapture_ExplicitByRef;
10158 SourceLocation EllipsisLoc;
10159 if (C->isPackExpansion()) {
10160 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10161 bool ShouldExpand = false;
10162 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010163 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010164 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10165 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010166 Unexpanded,
10167 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010168 NumExpansions)) {
10169 Invalid = true;
10170 continue;
10171 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010172
Douglas Gregor3e308b12012-02-14 19:27:52 +000010173 if (ShouldExpand) {
10174 // The transform has determined that we should perform an expansion;
10175 // transform and capture each of the arguments.
10176 // expansion of the pattern. Do so.
10177 VarDecl *Pack = C->getCapturedVar();
10178 for (unsigned I = 0; I != *NumExpansions; ++I) {
10179 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10180 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010181 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010182 Pack));
10183 if (!CapturedVar) {
10184 Invalid = true;
10185 continue;
10186 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010187
Douglas Gregor3e308b12012-02-14 19:27:52 +000010188 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010189 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10190 }
Richard Smith9467be42014-06-06 17:33:35 +000010191
10192 // FIXME: Retain a pack expansion if RetainExpansion is true.
10193
Douglas Gregor3e308b12012-02-14 19:27:52 +000010194 continue;
10195 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010196
Douglas Gregor3e308b12012-02-14 19:27:52 +000010197 EllipsisLoc = C->getEllipsisLoc();
10198 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010199
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010200 // Transform the captured variable.
10201 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010202 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010203 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010204 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010205 Invalid = true;
10206 continue;
10207 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010208
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010209 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010210 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10211 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010212 }
10213 if (!FinishedExplicitCaptures)
10214 getSema().finishLambdaExplicitCaptures(LSI);
10215
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010216 // Enter a new evaluation context to insulate the lambda from any
10217 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010218 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010219
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010220 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010221 StmtResult Body =
10222 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10223
10224 // ActOnLambda* will pop the function scope for us.
10225 FuncScopeCleanup.disable();
10226
Douglas Gregorb4328232012-02-14 00:00:48 +000010227 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010228 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010229 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010230 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010231 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010232 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010233
Richard Smithc38498f2015-04-27 21:27:54 +000010234 // Copy the LSI before ActOnFinishFunctionBody removes it.
10235 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10236 // the call operator.
10237 auto LSICopy = *LSI;
10238 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10239 /*IsInstantiation*/ true);
10240 SavedContext.pop();
10241
10242 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10243 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010244}
10245
10246template<typename Derived>
10247ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010248TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010249 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010250 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10251 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010252 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010253
Douglas Gregora16548e2009-08-11 05:31:07 +000010254 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010255 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010256 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010257 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010258 &ArgumentChanged))
10259 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010260
Douglas Gregora16548e2009-08-11 05:31:07 +000010261 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010262 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010263 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010264 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010265
Douglas Gregora16548e2009-08-11 05:31:07 +000010266 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010267 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010268 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010269 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010270 E->getRParenLoc());
10271}
Mike Stump11289f42009-09-09 15:08:12 +000010272
Douglas Gregora16548e2009-08-11 05:31:07 +000010273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010274ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010275TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010276 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010277 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010278 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010279 Expr *OldBase;
10280 QualType BaseType;
10281 QualType ObjectType;
10282 if (!E->isImplicitAccess()) {
10283 OldBase = E->getBase();
10284 Base = getDerived().TransformExpr(OldBase);
10285 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010287
John McCall2d74de92009-12-01 22:10:20 +000010288 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010289 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010290 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010291 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010292 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010293 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010294 ObjectTy,
10295 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010296 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010297 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010298
John McCallba7bf592010-08-24 05:47:05 +000010299 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010300 BaseType = ((Expr*) Base.get())->getType();
10301 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010302 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010303 BaseType = getDerived().TransformType(E->getBaseType());
10304 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10305 }
Mike Stump11289f42009-09-09 15:08:12 +000010306
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010307 // Transform the first part of the nested-name-specifier that qualifies
10308 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010309 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010310 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010311 E->getFirstQualifierFoundInScope(),
10312 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010313
Douglas Gregore16af532011-02-28 18:50:33 +000010314 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010315 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010316 QualifierLoc
10317 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10318 ObjectType,
10319 FirstQualifierInScope);
10320 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010321 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010322 }
Mike Stump11289f42009-09-09 15:08:12 +000010323
Abramo Bagnara7945c982012-01-27 09:46:47 +000010324 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10325
John McCall31f82722010-11-12 08:19:04 +000010326 // TODO: If this is a conversion-function-id, verify that the
10327 // destination type name (if present) resolves the same way after
10328 // instantiation as it did in the local scope.
10329
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010330 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010331 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010332 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010334
John McCall2d74de92009-12-01 22:10:20 +000010335 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010336 // This is a reference to a member without an explicitly-specified
10337 // template argument list. Optimize for this common case.
10338 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010339 Base.get() == OldBase &&
10340 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010341 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010342 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010343 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010344 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010345
John McCallb268a282010-08-23 23:25:46 +000010346 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010347 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010348 E->isArrow(),
10349 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010350 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010351 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010352 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010353 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010354 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010355 }
10356
John McCall6b51f282009-11-23 01:53:49 +000010357 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010358 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10359 E->getNumTemplateArgs(),
10360 TransArgs))
10361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010362
John McCallb268a282010-08-23 23:25:46 +000010363 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010364 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010365 E->isArrow(),
10366 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010367 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010368 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010369 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010370 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010371 &TransArgs);
10372}
10373
10374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010376TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010377 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010378 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010379 QualType BaseType;
10380 if (!Old->isImplicitAccess()) {
10381 Base = getDerived().TransformExpr(Old->getBase());
10382 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010383 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010384 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010385 Old->isArrow());
10386 if (Base.isInvalid())
10387 return ExprError();
10388 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010389 } else {
10390 BaseType = getDerived().TransformType(Old->getBaseType());
10391 }
John McCall10eae182009-11-30 22:42:35 +000010392
Douglas Gregor0da1d432011-02-28 20:01:57 +000010393 NestedNameSpecifierLoc QualifierLoc;
10394 if (Old->getQualifierLoc()) {
10395 QualifierLoc
10396 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10397 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010398 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010399 }
10400
Abramo Bagnara7945c982012-01-27 09:46:47 +000010401 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10402
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010403 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010404 Sema::LookupOrdinaryName);
10405
10406 // Transform all the decls.
10407 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10408 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010409 NamedDecl *InstD = static_cast<NamedDecl*>(
10410 getDerived().TransformDecl(Old->getMemberLoc(),
10411 *I));
John McCall84d87672009-12-10 09:41:52 +000010412 if (!InstD) {
10413 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10414 // This can happen because of dependent hiding.
10415 if (isa<UsingShadowDecl>(*I))
10416 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010417 else {
10418 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010419 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010420 }
John McCall84d87672009-12-10 09:41:52 +000010421 }
John McCall10eae182009-11-30 22:42:35 +000010422
10423 // Expand using declarations.
10424 if (isa<UsingDecl>(InstD)) {
10425 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010426 for (auto *I : UD->shadows())
10427 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010428 continue;
10429 }
10430
10431 R.addDecl(InstD);
10432 }
10433
10434 R.resolveKind();
10435
Douglas Gregor9262f472010-04-27 18:19:34 +000010436 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010437 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010438 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010439 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010440 Old->getMemberLoc(),
10441 Old->getNamingClass()));
10442 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010443 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010444
Douglas Gregorda7be082010-04-27 16:10:10 +000010445 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010446 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010447
John McCall10eae182009-11-30 22:42:35 +000010448 TemplateArgumentListInfo TransArgs;
10449 if (Old->hasExplicitTemplateArgs()) {
10450 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10451 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010452 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10453 Old->getNumTemplateArgs(),
10454 TransArgs))
10455 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010456 }
John McCall38836f02010-01-15 08:34:02 +000010457
10458 // FIXME: to do this check properly, we will need to preserve the
10459 // first-qualifier-in-scope here, just in case we had a dependent
10460 // base (and therefore couldn't do the check) and a
10461 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010462 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010463
John McCallb268a282010-08-23 23:25:46 +000010464 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010465 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010466 Old->getOperatorLoc(),
10467 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010468 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010469 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010470 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010471 R,
10472 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010473 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010474}
10475
10476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010477ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010478TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010479 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010480 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10481 if (SubExpr.isInvalid())
10482 return ExprError();
10483
10484 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010485 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010486
10487 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10488}
10489
10490template<typename Derived>
10491ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010492TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010493 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10494 if (Pattern.isInvalid())
10495 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010496
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010497 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010498 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010499
Douglas Gregorb8840002011-01-14 21:20:45 +000010500 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10501 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010502}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010503
10504template<typename Derived>
10505ExprResult
10506TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10507 // If E is not value-dependent, then nothing will change when we transform it.
10508 // Note: This is an instantiation-centric view.
10509 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010510 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010511
Richard Smithd784e682015-09-23 21:41:42 +000010512 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010513
Richard Smithd784e682015-09-23 21:41:42 +000010514 ArrayRef<TemplateArgument> PackArgs;
10515 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010516
Richard Smithd784e682015-09-23 21:41:42 +000010517 // Find the argument list to transform.
10518 if (E->isPartiallySubstituted()) {
10519 PackArgs = E->getPartialArguments();
10520 } else if (E->isValueDependent()) {
10521 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10522 bool ShouldExpand = false;
10523 bool RetainExpansion = false;
10524 Optional<unsigned> NumExpansions;
10525 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10526 Unexpanded,
10527 ShouldExpand, RetainExpansion,
10528 NumExpansions))
10529 return ExprError();
10530
10531 // If we need to expand the pack, build a template argument from it and
10532 // expand that.
10533 if (ShouldExpand) {
10534 auto *Pack = E->getPack();
10535 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10536 ArgStorage = getSema().Context.getPackExpansionType(
10537 getSema().Context.getTypeDeclType(TTPD), None);
10538 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10539 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10540 } else {
10541 auto *VD = cast<ValueDecl>(Pack);
10542 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10543 VK_RValue, E->getPackLoc());
10544 if (DRE.isInvalid())
10545 return ExprError();
10546 ArgStorage = new (getSema().Context) PackExpansionExpr(
10547 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10548 }
10549 PackArgs = ArgStorage;
10550 }
10551 }
10552
10553 // If we're not expanding the pack, just transform the decl.
10554 if (!PackArgs.size()) {
10555 auto *Pack = cast_or_null<NamedDecl>(
10556 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010557 if (!Pack)
10558 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010559 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10560 E->getPackLoc(),
10561 E->getRParenLoc(), None, None);
10562 }
10563
10564 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10565 E->getPackLoc());
10566 {
10567 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10568 typedef TemplateArgumentLocInventIterator<
10569 Derived, const TemplateArgument*> PackLocIterator;
10570 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10571 PackLocIterator(*this, PackArgs.end()),
10572 TransformedPackArgs, /*Uneval*/true))
10573 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010574 }
10575
Richard Smithd784e682015-09-23 21:41:42 +000010576 SmallVector<TemplateArgument, 8> Args;
10577 bool PartialSubstitution = false;
10578 for (auto &Loc : TransformedPackArgs.arguments()) {
10579 Args.push_back(Loc.getArgument());
10580 if (Loc.getArgument().isPackExpansion())
10581 PartialSubstitution = true;
10582 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010583
Richard Smithd784e682015-09-23 21:41:42 +000010584 if (PartialSubstitution)
10585 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10586 E->getPackLoc(),
10587 E->getRParenLoc(), None, Args);
10588
10589 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010590 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010591 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010592}
10593
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010594template<typename Derived>
10595ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010596TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10597 SubstNonTypeTemplateParmPackExpr *E) {
10598 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010599 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010600}
10601
10602template<typename Derived>
10603ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010604TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10605 SubstNonTypeTemplateParmExpr *E) {
10606 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010607 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010608}
10609
10610template<typename Derived>
10611ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010612TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10613 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010614 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010615}
10616
10617template<typename Derived>
10618ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010619TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10620 MaterializeTemporaryExpr *E) {
10621 return getDerived().TransformExpr(E->GetTemporaryExpr());
10622}
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
Douglas Gregorfe314812011-06-21 17:03:29 +000010624template<typename Derived>
10625ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010626TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10627 Expr *Pattern = E->getPattern();
10628
10629 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10630 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10631 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10632
10633 // Determine whether the set of unexpanded parameter packs can and should
10634 // be expanded.
10635 bool Expand = true;
10636 bool RetainExpansion = false;
10637 Optional<unsigned> NumExpansions;
10638 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10639 Pattern->getSourceRange(),
10640 Unexpanded,
10641 Expand, RetainExpansion,
10642 NumExpansions))
10643 return true;
10644
10645 if (!Expand) {
10646 // Do not expand any packs here, just transform and rebuild a fold
10647 // expression.
10648 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10649
10650 ExprResult LHS =
10651 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10652 if (LHS.isInvalid())
10653 return true;
10654
10655 ExprResult RHS =
10656 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10657 if (RHS.isInvalid())
10658 return true;
10659
10660 if (!getDerived().AlwaysRebuild() &&
10661 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10662 return E;
10663
10664 return getDerived().RebuildCXXFoldExpr(
10665 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10666 RHS.get(), E->getLocEnd());
10667 }
10668
10669 // The transform has determined that we should perform an elementwise
10670 // expansion of the pattern. Do so.
10671 ExprResult Result = getDerived().TransformExpr(E->getInit());
10672 if (Result.isInvalid())
10673 return true;
10674 bool LeftFold = E->isLeftFold();
10675
10676 // If we're retaining an expansion for a right fold, it is the innermost
10677 // component and takes the init (if any).
10678 if (!LeftFold && RetainExpansion) {
10679 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10680
10681 ExprResult Out = getDerived().TransformExpr(Pattern);
10682 if (Out.isInvalid())
10683 return true;
10684
10685 Result = getDerived().RebuildCXXFoldExpr(
10686 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10687 Result.get(), E->getLocEnd());
10688 if (Result.isInvalid())
10689 return true;
10690 }
10691
10692 for (unsigned I = 0; I != *NumExpansions; ++I) {
10693 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10694 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10695 ExprResult Out = getDerived().TransformExpr(Pattern);
10696 if (Out.isInvalid())
10697 return true;
10698
10699 if (Out.get()->containsUnexpandedParameterPack()) {
10700 // We still have a pack; retain a pack expansion for this slice.
10701 Result = getDerived().RebuildCXXFoldExpr(
10702 E->getLocStart(),
10703 LeftFold ? Result.get() : Out.get(),
10704 E->getOperator(), E->getEllipsisLoc(),
10705 LeftFold ? Out.get() : Result.get(),
10706 E->getLocEnd());
10707 } else if (Result.isUsable()) {
10708 // We've got down to a single element; build a binary operator.
10709 Result = getDerived().RebuildBinaryOperator(
10710 E->getEllipsisLoc(), E->getOperator(),
10711 LeftFold ? Result.get() : Out.get(),
10712 LeftFold ? Out.get() : Result.get());
10713 } else
10714 Result = Out;
10715
10716 if (Result.isInvalid())
10717 return true;
10718 }
10719
10720 // If we're retaining an expansion for a left fold, it is the outermost
10721 // component and takes the complete expansion so far as its init (if any).
10722 if (LeftFold && RetainExpansion) {
10723 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10724
10725 ExprResult Out = getDerived().TransformExpr(Pattern);
10726 if (Out.isInvalid())
10727 return true;
10728
10729 Result = getDerived().RebuildCXXFoldExpr(
10730 E->getLocStart(), Result.get(),
10731 E->getOperator(), E->getEllipsisLoc(),
10732 Out.get(), E->getLocEnd());
10733 if (Result.isInvalid())
10734 return true;
10735 }
10736
10737 // If we had no init and an empty pack, and we're not retaining an expansion,
10738 // then produce a fallback value or error.
10739 if (Result.isUnset())
10740 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10741 E->getOperator());
10742
10743 return Result;
10744}
10745
10746template<typename Derived>
10747ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010748TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10749 CXXStdInitializerListExpr *E) {
10750 return getDerived().TransformExpr(E->getSubExpr());
10751}
10752
10753template<typename Derived>
10754ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010755TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010756 return SemaRef.MaybeBindToTemporary(E);
10757}
10758
10759template<typename Derived>
10760ExprResult
10761TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010762 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010763}
10764
10765template<typename Derived>
10766ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010767TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10768 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10769 if (SubExpr.isInvalid())
10770 return ExprError();
10771
10772 if (!getDerived().AlwaysRebuild() &&
10773 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010774 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010775
10776 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010777}
10778
10779template<typename Derived>
10780ExprResult
10781TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10782 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010783 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010784 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010785 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010786 /*IsCall=*/false, Elements, &ArgChanged))
10787 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010788
Ted Kremeneke65b0862012-03-06 20:05:56 +000010789 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10790 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010791
Ted Kremeneke65b0862012-03-06 20:05:56 +000010792 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10793 Elements.data(),
10794 Elements.size());
10795}
10796
10797template<typename Derived>
10798ExprResult
10799TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010800 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010801 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010802 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010803 bool ArgChanged = false;
10804 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10805 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010806
Ted Kremeneke65b0862012-03-06 20:05:56 +000010807 if (OrigElement.isPackExpansion()) {
10808 // This key/value element is a pack expansion.
10809 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10810 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10811 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10812 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10813
10814 // Determine whether the set of unexpanded parameter packs can
10815 // and should be expanded.
10816 bool Expand = true;
10817 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010818 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10819 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010820 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10821 OrigElement.Value->getLocEnd());
10822 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10823 PatternRange,
10824 Unexpanded,
10825 Expand, RetainExpansion,
10826 NumExpansions))
10827 return ExprError();
10828
10829 if (!Expand) {
10830 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010831 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010832 // expansion.
10833 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10834 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10835 if (Key.isInvalid())
10836 return ExprError();
10837
10838 if (Key.get() != OrigElement.Key)
10839 ArgChanged = true;
10840
10841 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10842 if (Value.isInvalid())
10843 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010844
Ted Kremeneke65b0862012-03-06 20:05:56 +000010845 if (Value.get() != OrigElement.Value)
10846 ArgChanged = true;
10847
Chad Rosier1dcde962012-08-08 18:46:20 +000010848 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010849 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10850 };
10851 Elements.push_back(Expansion);
10852 continue;
10853 }
10854
10855 // Record right away that the argument was changed. This needs
10856 // to happen even if the array expands to nothing.
10857 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010858
Ted Kremeneke65b0862012-03-06 20:05:56 +000010859 // The transform has determined that we should perform an elementwise
10860 // expansion of the pattern. Do so.
10861 for (unsigned I = 0; I != *NumExpansions; ++I) {
10862 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10863 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10864 if (Key.isInvalid())
10865 return ExprError();
10866
10867 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10868 if (Value.isInvalid())
10869 return ExprError();
10870
Chad Rosier1dcde962012-08-08 18:46:20 +000010871 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010872 Key.get(), Value.get(), SourceLocation(), NumExpansions
10873 };
10874
10875 // If any unexpanded parameter packs remain, we still have a
10876 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010877 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010878 if (Key.get()->containsUnexpandedParameterPack() ||
10879 Value.get()->containsUnexpandedParameterPack())
10880 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010881
Ted Kremeneke65b0862012-03-06 20:05:56 +000010882 Elements.push_back(Element);
10883 }
10884
Richard Smith9467be42014-06-06 17:33:35 +000010885 // FIXME: Retain a pack expansion if RetainExpansion is true.
10886
Ted Kremeneke65b0862012-03-06 20:05:56 +000010887 // We've finished with this pack expansion.
10888 continue;
10889 }
10890
10891 // Transform and check key.
10892 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10893 if (Key.isInvalid())
10894 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010895
Ted Kremeneke65b0862012-03-06 20:05:56 +000010896 if (Key.get() != OrigElement.Key)
10897 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010898
Ted Kremeneke65b0862012-03-06 20:05:56 +000010899 // Transform and check value.
10900 ExprResult Value
10901 = getDerived().TransformExpr(OrigElement.Value);
10902 if (Value.isInvalid())
10903 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010904
Ted Kremeneke65b0862012-03-06 20:05:56 +000010905 if (Value.get() != OrigElement.Value)
10906 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010907
10908 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010909 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010910 };
10911 Elements.push_back(Element);
10912 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010913
Ted Kremeneke65b0862012-03-06 20:05:56 +000010914 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10915 return SemaRef.MaybeBindToTemporary(E);
10916
10917 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010918 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010919}
10920
Mike Stump11289f42009-09-09 15:08:12 +000010921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010922ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010923TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010924 TypeSourceInfo *EncodedTypeInfo
10925 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10926 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010928
Douglas Gregora16548e2009-08-11 05:31:07 +000010929 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010930 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010931 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010932
10933 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010934 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010935 E->getRParenLoc());
10936}
Mike Stump11289f42009-09-09 15:08:12 +000010937
Douglas Gregora16548e2009-08-11 05:31:07 +000010938template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010939ExprResult TreeTransform<Derived>::
10940TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010941 // This is a kind of implicit conversion, and it needs to get dropped
10942 // and recomputed for the same general reasons that ImplicitCastExprs
10943 // do, as well a more specific one: this expression is only valid when
10944 // it appears *immediately* as an argument expression.
10945 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010946}
10947
10948template<typename Derived>
10949ExprResult TreeTransform<Derived>::
10950TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010951 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010952 = getDerived().TransformType(E->getTypeInfoAsWritten());
10953 if (!TSInfo)
10954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010955
John McCall31168b02011-06-15 23:02:42 +000010956 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010957 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010959
John McCall31168b02011-06-15 23:02:42 +000010960 if (!getDerived().AlwaysRebuild() &&
10961 TSInfo == E->getTypeInfoAsWritten() &&
10962 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010963 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010964
John McCall31168b02011-06-15 23:02:42 +000010965 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010966 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010967 Result.get());
10968}
10969
10970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010972TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010973 // Transform arguments.
10974 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010975 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010976 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010977 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010978 &ArgChanged))
10979 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010980
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010981 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10982 // Class message: transform the receiver type.
10983 TypeSourceInfo *ReceiverTypeInfo
10984 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10985 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010986 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010987
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010988 // If nothing changed, just retain the existing message send.
10989 if (!getDerived().AlwaysRebuild() &&
10990 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010991 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010992
10993 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010994 SmallVector<SourceLocation, 16> SelLocs;
10995 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010996 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10997 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010998 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010999 E->getMethodDecl(),
11000 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011001 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011002 E->getRightLoc());
11003 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011004 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11005 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11006 // Build a new class message send to 'super'.
11007 SmallVector<SourceLocation, 16> SelLocs;
11008 E->getSelectorLocs(SelLocs);
11009 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11010 E->getSelector(),
11011 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011012 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011013 E->getMethodDecl(),
11014 E->getLeftLoc(),
11015 Args,
11016 E->getRightLoc());
11017 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011018
11019 // Instance message: transform the receiver
11020 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11021 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011022 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011023 = getDerived().TransformExpr(E->getInstanceReceiver());
11024 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011025 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011026
11027 // If nothing changed, just retain the existing message send.
11028 if (!getDerived().AlwaysRebuild() &&
11029 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011030 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011031
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011032 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011033 SmallVector<SourceLocation, 16> SelLocs;
11034 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011035 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011036 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011037 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011038 E->getMethodDecl(),
11039 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011040 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011041 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011042}
11043
Mike Stump11289f42009-09-09 15:08:12 +000011044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011046TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011047 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011048}
11049
Mike Stump11289f42009-09-09 15:08:12 +000011050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011052TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011053 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011054}
11055
Mike Stump11289f42009-09-09 15:08:12 +000011056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011058TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011059 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011060 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011061 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011062 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011063
11064 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011065
Douglas Gregord51d90d2010-04-26 20:11:03 +000011066 // If nothing changed, just retain the existing expression.
11067 if (!getDerived().AlwaysRebuild() &&
11068 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011069 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011070
John McCallb268a282010-08-23 23:25:46 +000011071 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011072 E->getLocation(),
11073 E->isArrow(), E->isFreeIvar());
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
John McCall47f29ea2009-12-08 09:21:05 +000011078TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011079 // 'super' and types never change. Property never changes. Just
11080 // retain the existing expression.
11081 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011082 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011083
Douglas Gregor9faee212010-04-26 20:47:02 +000011084 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011085 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011086 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011088
Douglas Gregor9faee212010-04-26 20:47:02 +000011089 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011090
Douglas Gregor9faee212010-04-26 20:47:02 +000011091 // If nothing changed, just retain the existing expression.
11092 if (!getDerived().AlwaysRebuild() &&
11093 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011094 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011095
John McCallb7bd14f2010-12-02 01:19:52 +000011096 if (E->isExplicitProperty())
11097 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11098 E->getExplicitProperty(),
11099 E->getLocation());
11100
11101 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011102 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011103 E->getImplicitPropertyGetter(),
11104 E->getImplicitPropertySetter(),
11105 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011106}
11107
Mike Stump11289f42009-09-09 15:08:12 +000011108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011109ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011110TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11111 // Transform the base expression.
11112 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11113 if (Base.isInvalid())
11114 return ExprError();
11115
11116 // Transform the key expression.
11117 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11118 if (Key.isInvalid())
11119 return ExprError();
11120
11121 // If nothing changed, just retain the existing expression.
11122 if (!getDerived().AlwaysRebuild() &&
11123 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011124 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011125
Chad Rosier1dcde962012-08-08 18:46:20 +000011126 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011127 Base.get(), Key.get(),
11128 E->getAtIndexMethodDecl(),
11129 E->setAtIndexMethodDecl());
11130}
11131
11132template<typename Derived>
11133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011134TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011135 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011136 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011137 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011138 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011139
Douglas Gregord51d90d2010-04-26 20:11:03 +000011140 // If nothing changed, just retain the existing expression.
11141 if (!getDerived().AlwaysRebuild() &&
11142 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011143 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011144
John McCallb268a282010-08-23 23:25:46 +000011145 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011146 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011147 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011148}
11149
Mike Stump11289f42009-09-09 15:08:12 +000011150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011152TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011153 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011154 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011155 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011156 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011157 SubExprs, &ArgumentChanged))
11158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011159
Douglas Gregora16548e2009-08-11 05:31:07 +000011160 if (!getDerived().AlwaysRebuild() &&
11161 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011162 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011163
Douglas Gregora16548e2009-08-11 05:31:07 +000011164 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011165 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011166 E->getRParenLoc());
11167}
11168
Mike Stump11289f42009-09-09 15:08:12 +000011169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011170ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011171TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11172 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11173 if (SrcExpr.isInvalid())
11174 return ExprError();
11175
11176 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11177 if (!Type)
11178 return ExprError();
11179
11180 if (!getDerived().AlwaysRebuild() &&
11181 Type == E->getTypeSourceInfo() &&
11182 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011183 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011184
11185 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11186 SrcExpr.get(), Type,
11187 E->getRParenLoc());
11188}
11189
11190template<typename Derived>
11191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011192TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011193 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011194
Craig Topperc3ec1492014-05-26 06:22:03 +000011195 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011196 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11197
11198 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011199 blockScope->TheDecl->setBlockMissingReturnType(
11200 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011201
Chris Lattner01cf8db2011-07-20 06:58:45 +000011202 SmallVector<ParmVarDecl*, 4> params;
11203 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011204
John McCallc8e321d2016-03-01 02:09:25 +000011205 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11206
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011207 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011208 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011209 if (getDerived().TransformFunctionTypeParams(
11210 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11211 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11212 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011213 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011214 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011215 }
John McCall490112f2011-02-04 18:33:18 +000011216
Eli Friedman34b49062012-01-26 03:00:14 +000011217 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011218 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011219
John McCallc8e321d2016-03-01 02:09:25 +000011220 auto epi = exprFunctionType->getExtProtoInfo();
11221 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11222
Jordan Rose5c382722013-03-08 21:51:21 +000011223 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011224 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011225 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011226
11227 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011228 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011229 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011230
11231 if (!oldBlock->blockMissingReturnType()) {
11232 blockScope->HasImplicitReturnType = false;
11233 blockScope->ReturnType = exprResultType;
11234 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011235
John McCall3882ace2011-01-05 12:14:39 +000011236 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011237 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011238 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011239 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011240 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011241 }
John McCall3882ace2011-01-05 12:14:39 +000011242
John McCall490112f2011-02-04 18:33:18 +000011243#ifndef NDEBUG
11244 // In builds with assertions, make sure that we captured everything we
11245 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011246 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011247 for (const auto &I : oldBlock->captures()) {
11248 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011249
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011250 // Ignore parameter packs.
11251 if (isa<ParmVarDecl>(oldCapture) &&
11252 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11253 continue;
John McCall490112f2011-02-04 18:33:18 +000011254
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011255 VarDecl *newCapture =
11256 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11257 oldCapture));
11258 assert(blockScope->CaptureMap.count(newCapture));
11259 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011260 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011261 }
11262#endif
11263
11264 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011265 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011266}
11267
Mike Stump11289f42009-09-09 15:08:12 +000011268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011269ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011270TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011271 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011272}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011273
11274template<typename Derived>
11275ExprResult
11276TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011277 QualType RetTy = getDerived().TransformType(E->getType());
11278 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011279 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011280 SubExprs.reserve(E->getNumSubExprs());
11281 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11282 SubExprs, &ArgumentChanged))
11283 return ExprError();
11284
11285 if (!getDerived().AlwaysRebuild() &&
11286 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011287 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011288
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011289 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011290 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011291}
Chad Rosier1dcde962012-08-08 18:46:20 +000011292
Douglas Gregora16548e2009-08-11 05:31:07 +000011293//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011294// Type reconstruction
11295//===----------------------------------------------------------------------===//
11296
Mike Stump11289f42009-09-09 15:08:12 +000011297template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011298QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11299 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011300 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011301 getDerived().getBaseEntity());
11302}
11303
Mike Stump11289f42009-09-09 15:08:12 +000011304template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011305QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11306 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011307 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011308 getDerived().getBaseEntity());
11309}
11310
Mike Stump11289f42009-09-09 15:08:12 +000011311template<typename Derived>
11312QualType
John McCall70dd5f62009-10-30 00:06:24 +000011313TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11314 bool WrittenAsLValue,
11315 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011316 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011317 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011318}
11319
11320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011321QualType
John McCall70dd5f62009-10-30 00:06:24 +000011322TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11323 QualType ClassType,
11324 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011325 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11326 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011327}
11328
11329template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011330QualType TreeTransform<Derived>::RebuildObjCObjectType(
11331 QualType BaseType,
11332 SourceLocation Loc,
11333 SourceLocation TypeArgsLAngleLoc,
11334 ArrayRef<TypeSourceInfo *> TypeArgs,
11335 SourceLocation TypeArgsRAngleLoc,
11336 SourceLocation ProtocolLAngleLoc,
11337 ArrayRef<ObjCProtocolDecl *> Protocols,
11338 ArrayRef<SourceLocation> ProtocolLocs,
11339 SourceLocation ProtocolRAngleLoc) {
11340 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11341 TypeArgs, TypeArgsRAngleLoc,
11342 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11343 ProtocolRAngleLoc,
11344 /*FailOnError=*/true);
11345}
11346
11347template<typename Derived>
11348QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11349 QualType PointeeType,
11350 SourceLocation Star) {
11351 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11352}
11353
11354template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011355QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011356TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11357 ArrayType::ArraySizeModifier SizeMod,
11358 const llvm::APInt *Size,
11359 Expr *SizeExpr,
11360 unsigned IndexTypeQuals,
11361 SourceRange BracketsRange) {
11362 if (SizeExpr || !Size)
11363 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11364 IndexTypeQuals, BracketsRange,
11365 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011366
11367 QualType Types[] = {
11368 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11369 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11370 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011371 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011372 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011373 QualType SizeType;
11374 for (unsigned I = 0; I != NumTypes; ++I)
11375 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11376 SizeType = Types[I];
11377 break;
11378 }
Mike Stump11289f42009-09-09 15:08:12 +000011379
Eli Friedman9562f392012-01-25 23:20:27 +000011380 // Note that we can return a VariableArrayType here in the case where
11381 // the element type was a dependent VariableArrayType.
11382 IntegerLiteral *ArraySize
11383 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11384 /*FIXME*/BracketsRange.getBegin());
11385 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011386 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011387 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011388}
Mike Stump11289f42009-09-09 15:08:12 +000011389
Douglas Gregord6ff3322009-08-04 16:50:30 +000011390template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011391QualType
11392TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011393 ArrayType::ArraySizeModifier SizeMod,
11394 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011395 unsigned IndexTypeQuals,
11396 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011397 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011398 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011399}
11400
11401template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011402QualType
Mike Stump11289f42009-09-09 15:08:12 +000011403TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011404 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011405 unsigned IndexTypeQuals,
11406 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011407 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011408 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011409}
Mike Stump11289f42009-09-09 15:08:12 +000011410
Douglas Gregord6ff3322009-08-04 16:50:30 +000011411template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011412QualType
11413TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011414 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011415 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011416 unsigned IndexTypeQuals,
11417 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011418 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011419 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011420 IndexTypeQuals, BracketsRange);
11421}
11422
11423template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011424QualType
11425TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011426 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011427 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011428 unsigned IndexTypeQuals,
11429 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011430 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011431 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011432 IndexTypeQuals, BracketsRange);
11433}
11434
11435template<typename Derived>
11436QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011437 unsigned NumElements,
11438 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011439 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011440 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011441}
Mike Stump11289f42009-09-09 15:08:12 +000011442
Douglas Gregord6ff3322009-08-04 16:50:30 +000011443template<typename Derived>
11444QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11445 unsigned NumElements,
11446 SourceLocation AttributeLoc) {
11447 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11448 NumElements, true);
11449 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011450 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11451 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011452 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011453}
Mike Stump11289f42009-09-09 15:08:12 +000011454
Douglas Gregord6ff3322009-08-04 16:50:30 +000011455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011456QualType
11457TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011458 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011459 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011460 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011461}
Mike Stump11289f42009-09-09 15:08:12 +000011462
Douglas Gregord6ff3322009-08-04 16:50:30 +000011463template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011464QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11465 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011466 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011467 const FunctionProtoType::ExtProtoInfo &EPI) {
11468 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011469 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011470 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011471 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011472}
Mike Stump11289f42009-09-09 15:08:12 +000011473
Douglas Gregord6ff3322009-08-04 16:50:30 +000011474template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011475QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11476 return SemaRef.Context.getFunctionNoProtoType(T);
11477}
11478
11479template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011480QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11481 assert(D && "no decl found");
11482 if (D->isInvalidDecl()) return QualType();
11483
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011484 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011485 TypeDecl *Ty;
11486 if (isa<UsingDecl>(D)) {
11487 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011488 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011489 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11490
11491 // A valid resolved using typename decl points to exactly one type decl.
11492 assert(++Using->shadow_begin() == Using->shadow_end());
11493 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011494
John McCallb96ec562009-12-04 22:46:56 +000011495 } else {
11496 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11497 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11498 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11499 }
11500
11501 return SemaRef.Context.getTypeDeclType(Ty);
11502}
11503
11504template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011505QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11506 SourceLocation Loc) {
11507 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011508}
11509
11510template<typename Derived>
11511QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11512 return SemaRef.Context.getTypeOfType(Underlying);
11513}
11514
11515template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011516QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11517 SourceLocation Loc) {
11518 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011519}
11520
11521template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011522QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11523 UnaryTransformType::UTTKind UKind,
11524 SourceLocation Loc) {
11525 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11526}
11527
11528template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011529QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011530 TemplateName Template,
11531 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011532 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011533 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011534}
Mike Stump11289f42009-09-09 15:08:12 +000011535
Douglas Gregor1135c352009-08-06 05:28:30 +000011536template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011537QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11538 SourceLocation KWLoc) {
11539 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11540}
11541
11542template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011543QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11544 SourceLocation KWLoc) {
11545 return SemaRef.BuildPipeType(ValueType, KWLoc);
11546}
11547
11548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011549TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011550TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011551 bool TemplateKW,
11552 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011553 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011554 Template);
11555}
11556
11557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011558TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011559TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11560 const IdentifierInfo &Name,
11561 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011562 QualType ObjectType,
11563 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011564 UnqualifiedId TemplateName;
11565 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011566 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011567 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011568 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011569 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011570 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011571 /*EnteringContext=*/false,
11572 Template);
John McCall31f82722010-11-12 08:19:04 +000011573 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011574}
Mike Stump11289f42009-09-09 15:08:12 +000011575
Douglas Gregora16548e2009-08-11 05:31:07 +000011576template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011577TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011578TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011579 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011580 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011581 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011582 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011583 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011584 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011585 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011586 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011587 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011588 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011589 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011590 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011591 /*EnteringContext=*/false,
11592 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011593 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011594}
Chad Rosier1dcde962012-08-08 18:46:20 +000011595
Douglas Gregor71395fa2009-11-04 00:56:37 +000011596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011597ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011598TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11599 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011600 Expr *OrigCallee,
11601 Expr *First,
11602 Expr *Second) {
11603 Expr *Callee = OrigCallee->IgnoreParenCasts();
11604 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011605
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011606 if (First->getObjectKind() == OK_ObjCProperty) {
11607 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11608 if (BinaryOperator::isAssignmentOp(Opc))
11609 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11610 First, Second);
11611 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11612 if (Result.isInvalid())
11613 return ExprError();
11614 First = Result.get();
11615 }
11616
11617 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11618 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11619 if (Result.isInvalid())
11620 return ExprError();
11621 Second = Result.get();
11622 }
11623
Douglas Gregora16548e2009-08-11 05:31:07 +000011624 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011625 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011626 if (!First->getType()->isOverloadableType() &&
11627 !Second->getType()->isOverloadableType())
11628 return getSema().CreateBuiltinArraySubscriptExpr(First,
11629 Callee->getLocStart(),
11630 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011631 } else if (Op == OO_Arrow) {
11632 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011633 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11634 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011635 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011636 // The argument is not of overloadable type, so try to create a
11637 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011638 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011639 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011640
John McCallb268a282010-08-23 23:25:46 +000011641 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011642 }
11643 } else {
John McCallb268a282010-08-23 23:25:46 +000011644 if (!First->getType()->isOverloadableType() &&
11645 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011646 // Neither of the arguments is an overloadable type, so try to
11647 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011648 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011649 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011650 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011651 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011653
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011654 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011655 }
11656 }
Mike Stump11289f42009-09-09 15:08:12 +000011657
11658 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011659 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011660 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011661
John McCallb268a282010-08-23 23:25:46 +000011662 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011663 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011664 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011665 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011666 // If we've resolved this to a particular non-member function, just call
11667 // that function. If we resolved it to a member function,
11668 // CreateOverloaded* will find that function for us.
11669 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11670 if (!isa<CXXMethodDecl>(ND))
11671 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011672 }
Mike Stump11289f42009-09-09 15:08:12 +000011673
Douglas Gregora16548e2009-08-11 05:31:07 +000011674 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011675 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011676 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011677
Douglas Gregora16548e2009-08-11 05:31:07 +000011678 // Create the overloaded operator invocation for unary operators.
11679 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011680 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011681 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011682 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011683 }
Mike Stump11289f42009-09-09 15:08:12 +000011684
Douglas Gregore9d62932011-07-15 16:25:15 +000011685 if (Op == OO_Subscript) {
11686 SourceLocation LBrace;
11687 SourceLocation RBrace;
11688
11689 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011690 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011691 LBrace = SourceLocation::getFromRawEncoding(
11692 NameLoc.CXXOperatorName.BeginOpNameLoc);
11693 RBrace = SourceLocation::getFromRawEncoding(
11694 NameLoc.CXXOperatorName.EndOpNameLoc);
11695 } else {
11696 LBrace = Callee->getLocStart();
11697 RBrace = OpLoc;
11698 }
11699
11700 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11701 First, Second);
11702 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011703
Douglas Gregora16548e2009-08-11 05:31:07 +000011704 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011705 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011706 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011707 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11708 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011710
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011711 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011712}
Mike Stump11289f42009-09-09 15:08:12 +000011713
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011714template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011715ExprResult
John McCallb268a282010-08-23 23:25:46 +000011716TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011717 SourceLocation OperatorLoc,
11718 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011719 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011720 TypeSourceInfo *ScopeType,
11721 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011722 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011723 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011724 QualType BaseType = Base->getType();
11725 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011726 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011727 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011728 !BaseType->getAs<PointerType>()->getPointeeType()
11729 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011730 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011731 return SemaRef.BuildPseudoDestructorExpr(
11732 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11733 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011734 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011735
Douglas Gregor678f90d2010-02-25 01:56:36 +000011736 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011737 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11738 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11739 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11740 NameInfo.setNamedTypeInfo(DestroyedType);
11741
Richard Smith8e4a3862012-05-15 06:15:11 +000011742 // The scope type is now known to be a valid nested name specifier
11743 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011744 if (ScopeType) {
11745 if (!ScopeType->getType()->getAs<TagType>()) {
11746 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11747 diag::err_expected_class_or_namespace)
11748 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11749 return ExprError();
11750 }
11751 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11752 CCLoc);
11753 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011754
Abramo Bagnara7945c982012-01-27 09:46:47 +000011755 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011756 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011757 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011758 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011759 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011760 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011761 /*TemplateArgs*/ nullptr,
11762 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011763}
11764
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011765template<typename Derived>
11766StmtResult
11767TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011768 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011769 CapturedDecl *CD = S->getCapturedDecl();
11770 unsigned NumParams = CD->getNumParams();
11771 unsigned ContextParamPos = CD->getContextParamPosition();
11772 SmallVector<Sema::CapturedParamNameType, 4> Params;
11773 for (unsigned I = 0; I < NumParams; ++I) {
11774 if (I != ContextParamPos) {
11775 Params.push_back(
11776 std::make_pair(
11777 CD->getParam(I)->getName(),
11778 getDerived().TransformType(CD->getParam(I)->getType())));
11779 } else {
11780 Params.push_back(std::make_pair(StringRef(), QualType()));
11781 }
11782 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011783 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011784 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011785 StmtResult Body;
11786 {
11787 Sema::CompoundScopeRAII CompoundScope(getSema());
11788 Body = getDerived().TransformStmt(S->getCapturedStmt());
11789 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011790
11791 if (Body.isInvalid()) {
11792 getSema().ActOnCapturedRegionError();
11793 return StmtError();
11794 }
11795
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011796 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011797}
11798
Douglas Gregord6ff3322009-08-04 16:50:30 +000011799} // end namespace clang
11800
Hans Wennborg59dbe862015-09-29 20:56:43 +000011801#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H