blob: b13dc34377d0701d16042ec5143f2fcd06eb7734 [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) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, nullptr, Cond, Then,
1180 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 /// \brief Start building a new switch statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001188 Sema::ConditionResult Cond) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001189 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, nullptr, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Attach the body to the switch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001197 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
1200
1201 /// \brief Build a new while statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001205 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1206 Sema::ConditionResult Cond, Stmt *Body) {
1207 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 /// \brief Build a new do-while statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 SourceLocation WhileLoc, SourceLocation LParenLoc,
1216 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001217 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1218 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
1220
1221 /// \brief Build a new for statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001226 Stmt *Init, Sema::ConditionResult Cond,
1227 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1228 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001229 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001230 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 /// \brief Build a new goto statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001237 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1238 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001239 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
1241
1242 /// \brief Build a new indirect goto statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001247 SourceLocation StarLoc,
1248 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001249 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 /// \brief Build a new return statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001256 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001257 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregorebe10102009-08-20 07:17:43 +00001260 /// \brief Build a new declaration statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001264 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001265 SourceLocation StartLoc, SourceLocation EndLoc) {
1266 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001267 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Anders Carlssonaaeef072010-01-24 05:50:09 +00001270 /// \brief Build a new inline asm statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001274 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1275 bool IsVolatile, unsigned NumOutputs,
1276 unsigned NumInputs, IdentifierInfo **Names,
1277 MultiExprArg Constraints, MultiExprArg Exprs,
1278 Expr *AsmString, MultiExprArg Clobbers,
1279 SourceLocation RParenLoc) {
1280 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1281 NumInputs, Names, Constraints, Exprs,
1282 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001283 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284
Chad Rosier32503022012-06-11 20:47:18 +00001285 /// \brief Build a new MS style inline asm statement.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001289 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001290 ArrayRef<Token> AsmToks,
1291 StringRef AsmString,
1292 unsigned NumOutputs, unsigned NumInputs,
1293 ArrayRef<StringRef> Constraints,
1294 ArrayRef<StringRef> Clobbers,
1295 ArrayRef<Expr*> Exprs,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1298 NumOutputs, NumInputs,
1299 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001300 }
1301
Richard Smith9f690bd2015-10-27 06:02:45 +00001302 /// \brief Build a new co_return statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1307 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1308 }
1309
1310 /// \brief Build a new co_await expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1315 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1316 }
1317
1318 /// \brief Build a new co_yield expression.
1319 ///
1320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
1322 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1323 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1324 }
1325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001332 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001333 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001334 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001335 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001336 }
1337
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001338 /// \brief Rebuild an Objective-C exception declaration.
1339 ///
1340 /// By default, performs semantic analysis to build the new declaration.
1341 /// Subclasses may override this routine to provide different behavior.
1342 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1343 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001344 return getSema().BuildObjCExceptionDecl(TInfo, T,
1345 ExceptionDecl->getInnerLocStart(),
1346 ExceptionDecl->getLocation(),
1347 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001355 SourceLocation RParenLoc,
1356 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001357 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001358 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001361
James Dennett2a4d13c2012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001366 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001367 Stmt *Body) {
1368 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001370
James Dennett2a4d13c2012-06-15 07:13:21 +00001371 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *Operand) {
1377 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001379
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001380 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001381 ///
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001384 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001385 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001386 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001387 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001388 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001389 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001390 return getSema().ActOnOpenMPExecutableDirective(
1391 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001392 }
1393
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001394 /// \brief Build a new OpenMP 'if' clause.
1395 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001396 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001397 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001398 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1399 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001400 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001401 SourceLocation NameModifierLoc,
1402 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001403 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001404 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1405 LParenLoc, NameModifierLoc, ColonLoc,
1406 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001407 }
1408
Alexey Bataev3778b602014-07-17 07:32:53 +00001409 /// \brief Build a new OpenMP 'final' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new OpenMP clause.
1412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1417 EndLoc);
1418 }
1419
Alexey Bataev568a8332014-03-06 06:15:19 +00001420 /// \brief Build a new OpenMP 'num_threads' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1425 SourceLocation StartLoc,
1426 SourceLocation LParenLoc,
1427 SourceLocation EndLoc) {
1428 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1429 LParenLoc, EndLoc);
1430 }
1431
Alexey Bataev62c87d22014-03-21 04:51:18 +00001432 /// \brief Build a new OpenMP 'safelen' clause.
1433 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001434 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001435 /// Subclasses may override this routine to provide different behavior.
1436 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1440 }
1441
Alexey Bataev66b15b52015-08-21 11:14:16 +00001442 /// \brief Build a new OpenMP 'simdlen' clause.
1443 ///
1444 /// By default, performs semantic analysis to build the new OpenMP clause.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1450 }
1451
Alexander Musman8bd31e62014-05-27 15:12:19 +00001452 /// \brief Build a new OpenMP 'collapse' clause.
1453 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001454 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1457 SourceLocation LParenLoc,
1458 SourceLocation EndLoc) {
1459 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1460 EndLoc);
1461 }
1462
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001463 /// \brief Build a new OpenMP 'default' clause.
1464 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001465 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001466 /// Subclasses may override this routine to provide different behavior.
1467 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1468 SourceLocation KindKwLoc,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1473 StartLoc, LParenLoc, EndLoc);
1474 }
1475
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001476 /// \brief Build a new OpenMP 'proc_bind' clause.
1477 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001478 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1481 SourceLocation KindKwLoc,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation EndLoc) {
1485 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1486 StartLoc, LParenLoc, EndLoc);
1487 }
1488
Alexey Bataev56dafe82014-06-20 07:16:17 +00001489 /// \brief Build a new OpenMP 'schedule' clause.
1490 ///
1491 /// By default, performs semantic analysis to build the new OpenMP clause.
1492 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001493 OMPClause *RebuildOMPScheduleClause(
1494 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1495 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1496 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1497 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001498 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001499 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1500 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001501 }
1502
Alexey Bataev10e775f2015-07-30 11:36:16 +00001503 /// \brief Build a new OpenMP 'ordered' clause.
1504 ///
1505 /// By default, performs semantic analysis to build the new OpenMP clause.
1506 /// Subclasses may override this routine to provide different behavior.
1507 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1508 SourceLocation EndLoc,
1509 SourceLocation LParenLoc, Expr *Num) {
1510 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1511 }
1512
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001513 /// \brief Build a new OpenMP 'private' clause.
1514 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001515 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001516 /// Subclasses may override this routine to provide different behavior.
1517 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1518 SourceLocation StartLoc,
1519 SourceLocation LParenLoc,
1520 SourceLocation EndLoc) {
1521 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1522 EndLoc);
1523 }
1524
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001525 /// \brief Build a new OpenMP 'firstprivate' clause.
1526 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001527 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001528 /// Subclasses may override this routine to provide different behavior.
1529 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1530 SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1534 EndLoc);
1535 }
1536
Alexander Musman1bb328c2014-06-04 13:06:39 +00001537 /// \brief Build a new OpenMP 'lastprivate' clause.
1538 ///
1539 /// By default, performs semantic analysis to build the new OpenMP clause.
1540 /// Subclasses may override this routine to provide different behavior.
1541 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1546 EndLoc);
1547 }
1548
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001549 /// \brief Build a new OpenMP 'shared' clause.
1550 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001551 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001552 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001553 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1554 SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1558 EndLoc);
1559 }
1560
Alexey Bataevc5e02582014-06-16 07:08:35 +00001561 /// \brief Build a new OpenMP 'reduction' clause.
1562 ///
1563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1566 SourceLocation StartLoc,
1567 SourceLocation LParenLoc,
1568 SourceLocation ColonLoc,
1569 SourceLocation EndLoc,
1570 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001571 const DeclarationNameInfo &ReductionId,
1572 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001573 return getSema().ActOnOpenMPReductionClause(
1574 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001575 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001576 }
1577
Alexander Musman8dba6642014-04-22 13:09:42 +00001578 /// \brief Build a new OpenMP 'linear' clause.
1579 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001580 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001581 /// Subclasses may override this routine to provide different behavior.
1582 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1583 SourceLocation StartLoc,
1584 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001585 OpenMPLinearClauseKind Modifier,
1586 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001587 SourceLocation ColonLoc,
1588 SourceLocation EndLoc) {
1589 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001590 Modifier, ModifierLoc, ColonLoc,
1591 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001592 }
1593
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001594 /// \brief Build a new OpenMP 'aligned' clause.
1595 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001596 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001597 /// Subclasses may override this routine to provide different behavior.
1598 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation ColonLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1604 LParenLoc, ColonLoc, EndLoc);
1605 }
1606
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001607 /// \brief Build a new OpenMP 'copyin' clause.
1608 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001609 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataevbae9a792014-06-27 10:37:06 +00001619 /// \brief Build a new OpenMP 'copyprivate' clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev6125da92014-07-21 11:26:11 +00001631 /// \brief Build a new OpenMP 'flush' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1636 SourceLocation StartLoc,
1637 SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1640 EndLoc);
1641 }
1642
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001643 /// \brief Build a new OpenMP 'depend' pseudo clause.
1644 ///
1645 /// By default, performs semantic analysis to build the new OpenMP clause.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *
1648 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1649 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc, SourceLocation LParenLoc,
1651 SourceLocation EndLoc) {
1652 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1653 StartLoc, LParenLoc, EndLoc);
1654 }
1655
Michael Wonge710d542015-08-07 16:16:36 +00001656 /// \brief Build a new OpenMP 'device' clause.
1657 ///
1658 /// By default, performs semantic analysis to build the new statement.
1659 /// Subclasses may override this routine to provide different behavior.
1660 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1661 SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001663 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001664 EndLoc);
1665 }
1666
Kelvin Li0bff7af2015-11-23 05:32:03 +00001667 /// \brief Build a new OpenMP 'map' clause.
1668 ///
1669 /// By default, performs semantic analysis to build the new OpenMP clause.
1670 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001671 OMPClause *
1672 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1673 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1674 SourceLocation MapLoc, SourceLocation ColonLoc,
1675 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1676 SourceLocation LParenLoc, SourceLocation EndLoc) {
1677 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1678 IsMapTypeImplicit, MapLoc, ColonLoc,
1679 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001680 }
1681
Kelvin Li099bb8c2015-11-24 20:50:12 +00001682 /// \brief Build a new OpenMP 'num_teams' clause.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
1686 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation EndLoc) {
1689 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1690 EndLoc);
1691 }
1692
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001693 /// \brief Build a new OpenMP 'thread_limit' clause.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1698 SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation EndLoc) {
1701 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1702 LParenLoc, EndLoc);
1703 }
1704
Alexey Bataeva0569352015-12-01 10:17:31 +00001705 /// \brief Build a new OpenMP 'priority' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new statement.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1713 EndLoc);
1714 }
1715
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001716 /// \brief Build a new OpenMP 'grainsize' clause.
1717 ///
1718 /// By default, performs semantic analysis to build the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
1720 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
1722 SourceLocation EndLoc) {
1723 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1724 EndLoc);
1725 }
1726
Alexey Bataev382967a2015-12-08 12:06:20 +00001727 /// \brief Build a new OpenMP 'num_tasks' clause.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
1731 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataev28c75412015-12-15 08:19:24 +00001738 /// \brief Build a new OpenMP 'hint' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new statement.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1746 }
1747
Carlo Bertollib4adf552016-01-15 18:50:31 +00001748 /// \brief Build a new OpenMP 'dist_schedule' clause.
1749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *
1753 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1754 Expr *ChunkSize, SourceLocation StartLoc,
1755 SourceLocation LParenLoc, SourceLocation KindLoc,
1756 SourceLocation CommaLoc, SourceLocation EndLoc) {
1757 return getSema().ActOnOpenMPDistScheduleClause(
1758 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1759 }
1760
Samuel Antao661c0902016-05-26 17:39:58 +00001761 /// \brief Build a new OpenMP 'to' clause.
1762 ///
1763 /// By default, performs semantic analysis to build the new statement.
1764 /// Subclasses may override this routine to provide different behavior.
1765 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1770 }
1771
Samuel Antaoec172c62016-05-26 17:49:04 +00001772 /// \brief Build a new OpenMP 'from' clause.
1773 ///
1774 /// By default, performs semantic analysis to build the new statement.
1775 /// Subclasses may override this routine to provide different behavior.
1776 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1777 SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1781 EndLoc);
1782 }
1783
James Dennett2a4d13c2012-06-15 07:13:21 +00001784 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001785 ///
1786 /// By default, performs semantic analysis to build the new statement.
1787 /// Subclasses may override this routine to provide different behavior.
1788 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1789 Expr *object) {
1790 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1791 }
1792
James Dennett2a4d13c2012-06-15 07:13:21 +00001793 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001794 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001795 /// By default, performs semantic analysis to build the new statement.
1796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001797 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001798 Expr *Object, Stmt *Body) {
1799 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001800 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001801
James Dennett2a4d13c2012-06-15 07:13:21 +00001802 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001803 ///
1804 /// By default, performs semantic analysis to build the new statement.
1805 /// Subclasses may override this routine to provide different behavior.
1806 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1807 Stmt *Body) {
1808 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1809 }
John McCall53848232011-07-27 01:07:15 +00001810
Douglas Gregorf68a5082010-04-22 23:10:45 +00001811 /// \brief Build a new Objective-C fast enumeration statement.
1812 ///
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001816 Stmt *Element,
1817 Expr *Collection,
1818 SourceLocation RParenLoc,
1819 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001820 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001821 Element,
John McCallb268a282010-08-23 23:25:46 +00001822 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001823 RParenLoc);
1824 if (ForEachStmt.isInvalid())
1825 return StmtError();
1826
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001827 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001829
Douglas Gregorebe10102009-08-20 07:17:43 +00001830 /// \brief Build a new C++ exception declaration.
1831 ///
1832 /// By default, performs semantic analysis to build the new decaration.
1833 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001834 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001835 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001836 SourceLocation StartLoc,
1837 SourceLocation IdLoc,
1838 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001839 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001840 StartLoc, IdLoc, Id);
1841 if (Var)
1842 getSema().CurContext->addDecl(Var);
1843 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001844 }
1845
1846 /// \brief Build a new C++ catch statement.
1847 ///
1848 /// By default, performs semantic analysis to build the new statement.
1849 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001850 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001851 VarDecl *ExceptionDecl,
1852 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001853 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1854 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregorebe10102009-08-20 07:17:43 +00001857 /// \brief Build a new C++ try statement.
1858 ///
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001861 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1862 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001863 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001864 }
Mike Stump11289f42009-09-09 15:08:12 +00001865
Richard Smith02e85f32011-04-14 22:09:26 +00001866 /// \brief Build a new C++0x range-based for statement.
1867 ///
1868 /// By default, performs semantic analysis to build the new statement.
1869 /// Subclasses may override this routine to provide different behavior.
1870 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001871 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001872 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001873 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001874 Expr *Cond, Expr *Inc,
1875 Stmt *LoopVar,
1876 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001877 // If we've just learned that the range is actually an Objective-C
1878 // collection, treat this as an Objective-C fast enumeration loop.
1879 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1880 if (RangeStmt->isSingleDecl()) {
1881 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001882 if (RangeVar->isInvalidDecl())
1883 return StmtError();
1884
Douglas Gregorf7106af2013-04-08 18:40:13 +00001885 Expr *RangeExpr = RangeVar->getInit();
1886 if (!RangeExpr->isTypeDependent() &&
1887 RangeExpr->getType()->isObjCObjectPointerType())
1888 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1889 RParenLoc);
1890 }
1891 }
1892 }
1893
Richard Smithcfd53b42015-10-22 06:13:50 +00001894 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001895 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001896 Cond, Inc, LoopVar, RParenLoc,
1897 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001898 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001899
1900 /// \brief Build a new C++0x range-based for statement.
1901 ///
1902 /// By default, performs semantic analysis to build the new statement.
1903 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001904 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001905 bool IsIfExists,
1906 NestedNameSpecifierLoc QualifierLoc,
1907 DeclarationNameInfo NameInfo,
1908 Stmt *Nested) {
1909 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1910 QualifierLoc, NameInfo, Nested);
1911 }
1912
Richard Smith02e85f32011-04-14 22:09:26 +00001913 /// \brief Attach body to a C++0x range-based for statement.
1914 ///
1915 /// By default, performs semantic analysis to finish the new statement.
1916 /// Subclasses may override this routine to provide different behavior.
1917 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1918 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001920
David Majnemerfad8f482013-10-15 09:33:02 +00001921 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001922 Stmt *TryBlock, Stmt *Handler) {
1923 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001924 }
1925
David Majnemerfad8f482013-10-15 09:33:02 +00001926 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001927 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001928 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001929 }
1930
David Majnemerfad8f482013-10-15 09:33:02 +00001931 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001932 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001933 }
1934
Alexey Bataevec474782014-10-09 08:45:04 +00001935 /// \brief Build a new predefined expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
1939 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1940 PredefinedExpr::IdentType IT) {
1941 return getSema().BuildPredefinedExpr(Loc, IT);
1942 }
1943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// \brief Build a new expression that references a declaration.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001949 LookupResult &R,
1950 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001951 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1952 }
1953
1954
1955 /// \brief Build a new expression that references a declaration.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001959 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001960 ValueDecl *VD,
1961 const DeclarationNameInfo &NameInfo,
1962 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001963 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001964 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001965
1966 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967
1968 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001977 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 }
1979
Douglas Gregorad8a3362009-09-04 17:36:40 +00001980 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001981 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001984 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001985 SourceLocation OperatorLoc,
1986 bool isArrow,
1987 CXXScopeSpec &SS,
1988 TypeSourceInfo *ScopeType,
1989 SourceLocation CCLoc,
1990 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001991 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001998 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001999 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002000 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregor882211c2010-04-28 22:16:22 +00002003 /// \brief Build a new builtin offsetof expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002007 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002008 TypeSourceInfo *Type,
2009 ArrayRef<Sema::OffsetOfComponent> Components,
2010 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002011 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002012 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002014
2015 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002016 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002020 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2021 SourceLocation OpLoc,
2022 UnaryExprOrTypeTrait ExprKind,
2023 SourceRange R) {
2024 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
2026
Peter Collingbournee190dee2011-03-11 19:24:49 +00002027 /// \brief Build a new sizeof, alignof or vec step expression with an
2028 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002029 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002032 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2033 UnaryExprOrTypeTrait ExprKind,
2034 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002036 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002039
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002040 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 }
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002044 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002047 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002049 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002051 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002052 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 RBracketLoc);
2054 }
2055
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002056 /// \brief Build a new array section expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
2060 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2061 Expr *LowerBound,
2062 SourceLocation ColonLoc, Expr *Length,
2063 SourceLocation RBracketLoc) {
2064 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2065 ColonLoc, Length, RBracketLoc);
2066 }
2067
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002074 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002075 Expr *ExecConfig = nullptr) {
2076 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002077 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 }
2079
2080 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002081 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002085 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002086 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002087 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002088 const DeclarationNameInfo &MemberNameInfo,
2089 ValueDecl *Member,
2090 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002091 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002092 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002093 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2094 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002095 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002096 // We have a reference to an unnamed field. This is always the
2097 // base of an anonymous struct/union member access, i.e. the
2098 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002099 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002100 assert(Member->getType()->isRecordType() &&
2101 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002102
Richard Smithcab9a7d2011-10-26 19:06:56 +00002103 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002104 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002105 QualifierLoc.getNestedNameSpecifier(),
2106 FoundDecl, Member);
2107 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002108 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002109 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002110 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002111 MemberExpr *ME = new (getSema().Context)
2112 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2113 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002114 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002115 }
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002117 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002118 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002119
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002120 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002121 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002122
John McCall16df1e52010-03-30 21:47:33 +00002123 // FIXME: this involves duplicating earlier analysis in a lot of
2124 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002125 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002126 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002127 R.resolveKind();
2128
John McCallb268a282010-08-23 23:25:46 +00002129 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002130 SS, TemplateKWLoc,
2131 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002132 R, ExplicitTemplateArgs,
2133 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 }
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002141 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002143 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 }
2145
2146 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002151 SourceLocation QuestionLoc,
2152 Expr *LHS,
2153 SourceLocation ColonLoc,
2154 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002155 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2156 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 }
2158
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002160 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002164 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002166 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002167 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002168 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 }
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002175 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002176 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002178 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002179 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002180 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 SourceLocation OpLoc,
2189 SourceLocation AccessorLoc,
2190 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002191
John McCall10eae182009-11-30 22:42:35 +00002192 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002193 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002194 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002195 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002196 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002197 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002198 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002199 /* TemplateArgs */ nullptr,
2200 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002204 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002208 MultiExprArg Inits,
2209 SourceLocation RBraceLoc,
2210 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002212 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002213 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002214 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002215
Douglas Gregord3d93062009-11-09 17:16:50 +00002216 // Patch in the result type we were given, which may have been computed
2217 // when the initial InitListExpr was built.
2218 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2219 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002220 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 MultiExprArg ArrayExprs,
2229 SourceLocation EqualOrColonLoc,
2230 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002231 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002232 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002234 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002236 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002237
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002238 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 }
Mike Stump11289f42009-09-09 15:08:12 +00002240
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002242 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 /// By default, builds the implicit value initialization without performing
2244 /// any semantic analysis. Subclasses may override this routine to provide
2245 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002247 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 }
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002255 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002256 SourceLocation RParenLoc) {
2257 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002258 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002259 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 }
2261
2262 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002263 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 /// By default, performs semantic analysis to build the new expression.
2265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002266 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002267 MultiExprArg SubExprs,
2268 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002269 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 }
Mike Stump11289f42009-09-09 15:08:12 +00002271
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002273 ///
2274 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// rather than attempting to map the label statement itself.
2276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002278 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002279 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002283 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002287 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002289 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 /// \brief Build a new __builtin_choose_expr expression.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002297 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 SourceLocation RParenLoc) {
2299 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002300 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 RParenLoc);
2302 }
Mike Stump11289f42009-09-09 15:08:12 +00002303
Peter Collingbourne91147592011-04-15 00:35:48 +00002304 /// \brief Build a new generic selection expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
2308 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2309 SourceLocation DefaultLoc,
2310 SourceLocation RParenLoc,
2311 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002312 ArrayRef<TypeSourceInfo *> Types,
2313 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002314 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002315 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002316 }
2317
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 /// \brief Build a new overloaded operator call expression.
2319 ///
2320 /// By default, performs semantic analysis to build the new expression.
2321 /// The semantic analysis provides the behavior of template instantiation,
2322 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002323 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// argument-dependent lookup, etc. Subclasses may override this routine to
2325 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002326 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002328 Expr *Callee,
2329 Expr *First,
2330 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002331
2332 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 /// reinterpret_cast.
2334 ///
2335 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002336 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002338 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 Stmt::StmtClass Class,
2340 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002341 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 SourceLocation RAngleLoc,
2343 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 SourceLocation RParenLoc) {
2346 switch (Class) {
2347 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002348 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002349 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002350 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002351
2352 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002353 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002354 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002355 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002358 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002359 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002360 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002364 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002365 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002366 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002367
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002369 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 }
Mike Stump11289f42009-09-09 15:08:12 +00002372
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 /// \brief Build a new C++ static_cast expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002379 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 SourceLocation RAngleLoc,
2381 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002382 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002384 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002385 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002386 SourceRange(LAngleLoc, RAngleLoc),
2387 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
2389
2390 /// \brief Build a new C++ dynamic_cast expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002396 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 SourceLocation RAngleLoc,
2398 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002399 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002401 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002402 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002403 SourceRange(LAngleLoc, RAngleLoc),
2404 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
2406
2407 /// \brief Build a new C++ reinterpret_cast expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002411 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002413 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002414 SourceLocation RAngleLoc,
2415 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002416 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002418 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002419 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002420 SourceRange(LAngleLoc, RAngleLoc),
2421 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 }
2423
2424 /// \brief Build a new C++ const_cast expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002430 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 SourceLocation RAngleLoc,
2432 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002433 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002436 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002437 SourceRange(LAngleLoc, RAngleLoc),
2438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 /// \brief Build a new C++ functional-style cast expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002445 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2446 SourceLocation LParenLoc,
2447 Expr *Sub,
2448 SourceLocation RParenLoc) {
2449 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002450 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 RParenLoc);
2452 }
Mike Stump11289f42009-09-09 15:08:12 +00002453
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 /// \brief Build a new C++ typeid(type) expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002458 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002459 SourceLocation TypeidLoc,
2460 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002462 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002463 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 }
Mike Stump11289f42009-09-09 15:08:12 +00002465
Francois Pichet9f4f2072010-09-08 12:20:18 +00002466
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 /// \brief Build a new C++ typeid(expr) expression.
2468 ///
2469 /// By default, performs semantic analysis to build the new expression.
2470 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002471 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002472 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002473 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002474 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002475 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002476 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002477 }
2478
Francois Pichet9f4f2072010-09-08 12:20:18 +00002479 /// \brief Build a new C++ __uuidof(type) expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2484 SourceLocation TypeidLoc,
2485 TypeSourceInfo *Operand,
2486 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002487 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002488 RParenLoc);
2489 }
2490
2491 /// \brief Build a new C++ __uuidof(expr) expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
2495 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2496 SourceLocation TypeidLoc,
2497 Expr *Operand,
2498 SourceLocation RParenLoc) {
2499 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2500 RParenLoc);
2501 }
2502
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 /// \brief Build a new C++ "this" expression.
2504 ///
2505 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002506 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002509 QualType ThisType,
2510 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002511 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002512 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 }
2514
2515 /// \brief Build a new C++ throw expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002519 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2520 bool IsThrownVariableInScope) {
2521 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
2523
2524 /// \brief Build a new C++ default-argument expression.
2525 ///
2526 /// By default, builds a new default-argument expression, which does not
2527 /// require any semantic analysis. Subclasses may override this routine to
2528 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002529 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002530 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002531 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 }
2533
Richard Smith852c9db2013-04-20 22:23:05 +00002534 /// \brief Build a new C++11 default-initialization expression.
2535 ///
2536 /// By default, builds a new default field initialization expression, which
2537 /// does not require any semantic analysis. Subclasses may override this
2538 /// routine to provide different behavior.
2539 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2540 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002541 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002542 }
2543
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 /// \brief Build a new C++ zero-initialization expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002548 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2549 SourceLocation LParenLoc,
2550 SourceLocation RParenLoc) {
2551 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002552 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 }
Mike Stump11289f42009-09-09 15:08:12 +00002554
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 /// \brief Build a new C++ "new" expression.
2556 ///
2557 /// By default, performs semantic analysis to build the new expression.
2558 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002559 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002560 bool UseGlobal,
2561 SourceLocation PlacementLParen,
2562 MultiExprArg PlacementArgs,
2563 SourceLocation PlacementRParen,
2564 SourceRange TypeIdParens,
2565 QualType AllocatedType,
2566 TypeSourceInfo *AllocatedTypeInfo,
2567 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002568 SourceRange DirectInitRange,
2569 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002570 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002572 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002574 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002575 AllocatedType,
2576 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002577 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002578 DirectInitRange,
2579 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 }
Mike Stump11289f42009-09-09 15:08:12 +00002581
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 /// \brief Build a new C++ "delete" expression.
2583 ///
2584 /// By default, performs semantic analysis to build the new expression.
2585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002586 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 bool IsGlobalDelete,
2588 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002589 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002591 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 }
Mike Stump11289f42009-09-09 15:08:12 +00002593
Douglas Gregor29c42f22012-02-24 07:38:34 +00002594 /// \brief Build a new type trait expression.
2595 ///
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
2598 ExprResult RebuildTypeTrait(TypeTrait Trait,
2599 SourceLocation StartLoc,
2600 ArrayRef<TypeSourceInfo *> Args,
2601 SourceLocation RParenLoc) {
2602 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002604
John Wiegley6242b6a2011-04-28 00:16:57 +00002605 /// \brief Build a new array type trait expression.
2606 ///
2607 /// By default, performs semantic analysis to build the new expression.
2608 /// Subclasses may override this routine to provide different behavior.
2609 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2610 SourceLocation StartLoc,
2611 TypeSourceInfo *TSInfo,
2612 Expr *DimExpr,
2613 SourceLocation RParenLoc) {
2614 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2615 }
2616
John Wiegleyf9f65842011-04-25 06:54:41 +00002617 /// \brief Build a new expression trait expression.
2618 ///
2619 /// By default, performs semantic analysis to build the new expression.
2620 /// Subclasses may override this routine to provide different behavior.
2621 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2622 SourceLocation StartLoc,
2623 Expr *Queried,
2624 SourceLocation RParenLoc) {
2625 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2626 }
2627
Mike Stump11289f42009-09-09 15:08:12 +00002628 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002629 /// expression.
2630 ///
2631 /// By default, performs semantic analysis to build the new expression.
2632 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002633 ExprResult RebuildDependentScopeDeclRefExpr(
2634 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002635 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002637 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002638 bool IsAddressOfOperand,
2639 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002641 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002642
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002643 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002644 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2645 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002646
Reid Kleckner32506ed2014-06-12 23:03:48 +00002647 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002648 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002649 }
2650
2651 /// \brief Build a new template-id expression.
2652 ///
2653 /// By default, performs semantic analysis to build the new expression.
2654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002655 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002656 SourceLocation TemplateKWLoc,
2657 LookupResult &R,
2658 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002659 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002660 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2661 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 }
2663
2664 /// \brief Build a new object-construction expression.
2665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002668 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002669 SourceLocation Loc,
2670 CXXConstructorDecl *Constructor,
2671 bool IsElidable,
2672 MultiExprArg Args,
2673 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002674 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002675 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002676 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002677 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002678 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002679 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002680 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002681 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002682 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002683
Richard Smithc83bf822016-06-10 00:58:19 +00002684 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002685 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002686 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002687 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002688 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002689 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002690 RequiresZeroInit, ConstructKind,
2691 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002692 }
2693
Richard Smith5179eb72016-06-28 19:03:57 +00002694 /// \brief Build a new implicit construction via inherited constructor
2695 /// expression.
2696 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2697 CXXConstructorDecl *Constructor,
2698 bool ConstructsVBase,
2699 bool InheritedFromVBase) {
2700 return new (getSema().Context) CXXInheritedCtorInitExpr(
2701 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2702 }
2703
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 /// \brief Build a new object-construction expression.
2705 ///
2706 /// By default, performs semantic analysis to build the new expression.
2707 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002708 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2709 SourceLocation LParenLoc,
2710 MultiExprArg Args,
2711 SourceLocation RParenLoc) {
2712 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002713 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002714 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002715 RParenLoc);
2716 }
2717
2718 /// \brief Build a new object-construction expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002722 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2723 SourceLocation LParenLoc,
2724 MultiExprArg Args,
2725 SourceLocation RParenLoc) {
2726 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002727 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002728 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 RParenLoc);
2730 }
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 /// \brief Build a new member reference expression.
2733 ///
2734 /// By default, performs semantic analysis to build the new expression.
2735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002736 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002737 QualType BaseType,
2738 bool IsArrow,
2739 SourceLocation OperatorLoc,
2740 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002741 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002742 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002743 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002744 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002745 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002746 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002747
John McCallb268a282010-08-23 23:25:46 +00002748 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002749 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002750 SS, TemplateKWLoc,
2751 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002752 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002753 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 }
2755
John McCall10eae182009-11-30 22:42:35 +00002756 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002760 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2761 SourceLocation OperatorLoc,
2762 bool IsArrow,
2763 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002764 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002765 NamedDecl *FirstQualifierInScope,
2766 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002767 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002768 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002769 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCallb268a282010-08-23 23:25:46 +00002771 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002772 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002773 SS, TemplateKWLoc,
2774 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002775 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002776 }
Mike Stump11289f42009-09-09 15:08:12 +00002777
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002778 /// \brief Build a new noexcept expression.
2779 ///
2780 /// By default, performs semantic analysis to build the new expression.
2781 /// Subclasses may override this routine to provide different behavior.
2782 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2783 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2784 }
2785
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002786 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002787 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2788 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002789 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002790 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002791 Optional<unsigned> Length,
2792 ArrayRef<TemplateArgument> PartialArgs) {
2793 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2794 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002795 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002796
Patrick Beard0caa3942012-04-19 00:25:12 +00002797 /// \brief Build a new Objective-C boxed expression.
2798 ///
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
2801 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2802 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002804
Ted Kremeneke65b0862012-03-06 20:05:56 +00002805 /// \brief Build a new Objective-C array literal.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2809 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2810 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002811 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002812 MultiExprArg(Elements, NumElements));
2813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
2815 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002816 Expr *Base, Expr *Key,
2817 ObjCMethodDecl *getterMethod,
2818 ObjCMethodDecl *setterMethod) {
2819 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2820 getterMethod, setterMethod);
2821 }
2822
2823 /// \brief Build a new Objective-C dictionary literal.
2824 ///
2825 /// By default, performs semantic analysis to build the new expression.
2826 /// Subclasses may override this routine to provide different behavior.
2827 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002828 MutableArrayRef<ObjCDictionaryElement> Elements) {
2829 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002831
James Dennett2a4d13c2012-06-15 07:13:21 +00002832 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002833 ///
2834 /// By default, performs semantic analysis to build the new expression.
2835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002836 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002837 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002838 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002839 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002840 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002841
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002842 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002843 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002844 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002845 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002846 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002847 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002848 MultiExprArg Args,
2849 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002850 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2851 ReceiverTypeInfo->getType(),
2852 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002853 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002854 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002855 }
2856
2857 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002858 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002859 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002860 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002861 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002862 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002863 MultiExprArg Args,
2864 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002865 return SemaRef.BuildInstanceMessage(Receiver,
2866 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002867 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002868 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002869 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002870 }
2871
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002872 /// \brief Build a new Objective-C instance/class message to 'super'.
2873 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2874 Selector Sel,
2875 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002876 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002877 ObjCMethodDecl *Method,
2878 SourceLocation LBracLoc,
2879 MultiExprArg Args,
2880 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002881 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002882 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002883 SuperLoc,
2884 Sel, Method, LBracLoc, SelectorLocs,
2885 RBracLoc, Args)
2886 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002887 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002888 SuperLoc,
2889 Sel, Method, LBracLoc, SelectorLocs,
2890 RBracLoc, Args);
2891
2892
2893 }
2894
Douglas Gregord51d90d2010-04-26 20:11:03 +00002895 /// \brief Build a new Objective-C ivar reference expression.
2896 ///
2897 /// By default, performs semantic analysis to build the new expression.
2898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002899 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002900 SourceLocation IvarLoc,
2901 bool IsArrow, bool IsFreeIvar) {
2902 // FIXME: We lose track of the IsFreeIvar bit.
2903 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002904 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2905 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002906 /*FIXME:*/IvarLoc, IsArrow,
2907 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002908 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002909 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002910 /*TemplateArgs=*/nullptr,
2911 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002912 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002913
2914 /// \brief Build a new Objective-C property reference expression.
2915 ///
2916 /// By default, performs semantic analysis to build the new expression.
2917 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002919 ObjCPropertyDecl *Property,
2920 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002921 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002922 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2923 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2924 /*FIXME:*/PropertyLoc,
2925 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002926 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002927 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002928 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002929 /*TemplateArgs=*/nullptr,
2930 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002932
John McCallb7bd14f2010-12-02 01:19:52 +00002933 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002934 ///
2935 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002936 /// Subclasses may override this routine to provide different behavior.
2937 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2938 ObjCMethodDecl *Getter,
2939 ObjCMethodDecl *Setter,
2940 SourceLocation PropertyLoc) {
2941 // Since these expressions can only be value-dependent, we do not
2942 // need to perform semantic analysis again.
2943 return Owned(
2944 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2945 VK_LValue, OK_ObjCProperty,
2946 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002947 }
2948
Douglas Gregord51d90d2010-04-26 20:11:03 +00002949 /// \brief Build a new Objective-C "isa" expression.
2950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002953 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002954 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002955 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002956 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2957 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002958 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002959 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002960 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002961 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002962 /*TemplateArgs=*/nullptr,
2963 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
Douglas Gregora16548e2009-08-11 05:31:07 +00002966 /// \brief Build a new shuffle vector expression.
2967 ///
2968 /// By default, performs semantic analysis to build the new expression.
2969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002970 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002971 MultiExprArg SubExprs,
2972 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002973 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002974 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002975 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2976 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2977 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002978 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002979
Douglas Gregora16548e2009-08-11 05:31:07 +00002980 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002981 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002982 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2983 SemaRef.Context.BuiltinFnTy,
2984 VK_RValue, BuiltinLoc);
2985 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2986 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002987 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002988
2989 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002990 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002991 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002992 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002993
Douglas Gregora16548e2009-08-11 05:31:07 +00002994 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002995 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002996 }
John McCall31f82722010-11-12 08:19:04 +00002997
Hal Finkelc4d7c822013-09-18 03:29:45 +00002998 /// \brief Build a new convert vector expression.
2999 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3000 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3001 SourceLocation RParenLoc) {
3002 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3003 BuiltinLoc, RParenLoc);
3004 }
3005
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003006 /// \brief Build a new template argument pack expansion.
3007 ///
3008 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003009 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003010 /// different behavior.
3011 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003012 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003013 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003015 case TemplateArgument::Expression: {
3016 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003017 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3018 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003019 if (Result.isInvalid())
3020 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregor98318c22011-01-03 21:37:45 +00003022 return TemplateArgumentLoc(Result.get(), Result.get());
3023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003024
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003026 return TemplateArgumentLoc(TemplateArgument(
3027 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003028 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003029 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003030 Pattern.getTemplateNameLoc(),
3031 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003032
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003033 case TemplateArgument::Null:
3034 case TemplateArgument::Integral:
3035 case TemplateArgument::Declaration:
3036 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003037 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003038 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003042 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003043 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003044 EllipsisLoc,
3045 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003046 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3047 Expansion);
3048 break;
3049 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003050
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003051 return TemplateArgumentLoc();
3052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
Douglas Gregor968f23a2011-01-03 19:31:53 +00003054 /// \brief Build a new expression pack expansion.
3055 ///
3056 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003057 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003058 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003059 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003060 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003061 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003063
Richard Smith0f0af192014-11-08 05:07:16 +00003064 /// \brief Build a new C++1z fold-expression.
3065 ///
3066 /// By default, performs semantic analysis in order to build a new fold
3067 /// expression.
3068 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3069 BinaryOperatorKind Operator,
3070 SourceLocation EllipsisLoc, Expr *RHS,
3071 SourceLocation RParenLoc) {
3072 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3073 RHS, RParenLoc);
3074 }
3075
3076 /// \brief Build an empty C++1z fold-expression with the given operator.
3077 ///
3078 /// By default, produces the fallback value for the fold-expression, or
3079 /// produce an error if there is no fallback value.
3080 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3081 BinaryOperatorKind Operator) {
3082 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3083 }
3084
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003085 /// \brief Build a new atomic operation expression.
3086 ///
3087 /// By default, performs semantic analysis to build the new expression.
3088 /// Subclasses may override this routine to provide different behavior.
3089 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3090 MultiExprArg SubExprs,
3091 QualType RetTy,
3092 AtomicExpr::AtomicOp Op,
3093 SourceLocation RParenLoc) {
3094 // Just create the expression; there is not any interesting semantic
3095 // analysis here because we can't actually build an AtomicExpr until
3096 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003097 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003098 RParenLoc);
3099 }
3100
John McCall31f82722010-11-12 08:19:04 +00003101private:
Douglas Gregor14454802011-02-25 02:25:35 +00003102 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3103 QualType ObjectType,
3104 NamedDecl *FirstQualifierInScope,
3105 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003106
3107 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3108 QualType ObjectType,
3109 NamedDecl *FirstQualifierInScope,
3110 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003111
3112 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3113 NamedDecl *FirstQualifierInScope,
3114 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115};
Douglas Gregora16548e2009-08-11 05:31:07 +00003116
Douglas Gregorebe10102009-08-20 07:17:43 +00003117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003118StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003119 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003120 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003121
Douglas Gregorebe10102009-08-20 07:17:43 +00003122 switch (S->getStmtClass()) {
3123 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003124
Douglas Gregorebe10102009-08-20 07:17:43 +00003125 // Transform individual statement nodes
3126#define STMT(Node, Parent) \
3127 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003128#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003129#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003130#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Transform expressions by calling TransformExpr.
3133#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003134#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003135#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003136#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003137 {
John McCalldadc5752010-08-24 06:29:42 +00003138 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003139 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003141
Richard Smith945f8d32013-01-14 22:39:08 +00003142 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 }
Mike Stump11289f42009-09-09 15:08:12 +00003144 }
3145
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003146 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003147}
Mike Stump11289f42009-09-09 15:08:12 +00003148
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003149template<typename Derived>
3150OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3151 if (!S)
3152 return S;
3153
3154 switch (S->getClauseKind()) {
3155 default: break;
3156 // Transform individual clause nodes
3157#define OPENMP_CLAUSE(Name, Class) \
3158 case OMPC_ ## Name : \
3159 return getDerived().Transform ## Class(cast<Class>(S));
3160#include "clang/Basic/OpenMPKinds.def"
3161 }
3162
3163 return S;
3164}
3165
Mike Stump11289f42009-09-09 15:08:12 +00003166
Douglas Gregore922c772009-08-04 22:27:00 +00003167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003168ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003169 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003170 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003171
3172 switch (E->getStmtClass()) {
3173 case Stmt::NoStmtClass: break;
3174#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003175#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003176#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003177 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003178#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003179 }
3180
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003181 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003182}
3183
3184template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003185ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003186 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003187 // Initializers are instantiated like expressions, except that various outer
3188 // layers are stripped.
3189 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003190 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003191
3192 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3193 Init = ExprTemp->getSubExpr();
3194
Richard Smithe6ca4752013-05-30 22:40:16 +00003195 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3196 Init = MTE->GetTemporaryExpr();
3197
Richard Smithd59b8322012-12-19 01:39:02 +00003198 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3199 Init = Binder->getSubExpr();
3200
3201 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3202 Init = ICE->getSubExprAsWritten();
3203
Richard Smithcc1b96d2013-06-12 22:31:48 +00003204 if (CXXStdInitializerListExpr *ILE =
3205 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003206 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003207
Richard Smithc6abd962014-07-25 01:12:44 +00003208 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003209 // InitListExprs. Other forms of copy-initialization will be a no-op if
3210 // the initializer is already the right type.
3211 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003212 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003213 return getDerived().TransformExpr(Init);
3214
3215 // Revert value-initialization back to empty parens.
3216 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3217 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003218 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003219 Parens.getEnd());
3220 }
3221
3222 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3223 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003224 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003225 SourceLocation());
3226
3227 // Revert initialization by constructor back to a parenthesized or braced list
3228 // of expressions. Any other form of initializer can just be reused directly.
3229 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003230 return getDerived().TransformExpr(Init);
3231
Richard Smithf8adcdc2014-07-17 05:12:35 +00003232 // If the initialization implicitly converted an initializer list to a
3233 // std::initializer_list object, unwrap the std::initializer_list too.
3234 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003235 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003236
Richard Smithd59b8322012-12-19 01:39:02 +00003237 SmallVector<Expr*, 8> NewArgs;
3238 bool ArgChanged = false;
3239 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003240 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003241 return ExprError();
3242
3243 // If this was list initialization, revert to list form.
3244 if (Construct->isListInitialization())
3245 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3246 Construct->getLocEnd(),
3247 Construct->getType());
3248
Richard Smithd59b8322012-12-19 01:39:02 +00003249 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003250 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003251 if (Parens.isInvalid()) {
3252 // This was a variable declaration's initialization for which no initializer
3253 // was specified.
3254 assert(NewArgs.empty() &&
3255 "no parens or braces but have direct init with arguments?");
3256 return ExprEmpty();
3257 }
Richard Smithd59b8322012-12-19 01:39:02 +00003258 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3259 Parens.getEnd());
3260}
3261
3262template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003263bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003264 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003265 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003266 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003267 bool *ArgChanged) {
3268 for (unsigned I = 0; I != NumInputs; ++I) {
3269 // If requested, drop call arguments that need to be dropped.
3270 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3271 if (ArgChanged)
3272 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregora3efea12011-01-03 19:04:46 +00003274 break;
3275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor968f23a2011-01-03 19:31:53 +00003277 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3278 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Chris Lattner01cf8db2011-07-20 06:58:45 +00003280 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003281 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3282 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 // Determine whether the set of unexpanded parameter packs can and should
3285 // be expanded.
3286 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003287 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003288 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3289 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003290 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3291 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003292 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003293 Expand, RetainExpansion,
3294 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003295 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Douglas Gregor968f23a2011-01-03 19:31:53 +00003297 if (!Expand) {
3298 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003299 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003300 // expansion.
3301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3302 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3303 if (OutPattern.isInvalid())
3304 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
3306 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003307 Expansion->getEllipsisLoc(),
3308 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003309 if (Out.isInvalid())
3310 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor968f23a2011-01-03 19:31:53 +00003312 if (ArgChanged)
3313 *ArgChanged = true;
3314 Outputs.push_back(Out.get());
3315 continue;
3316 }
John McCall542e7c62011-07-06 07:30:07 +00003317
3318 // Record right away that the argument was changed. This needs
3319 // to happen even if the array expands to nothing.
3320 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregor968f23a2011-01-03 19:31:53 +00003322 // The transform has determined that we should perform an elementwise
3323 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003324 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3326 ExprResult Out = getDerived().TransformExpr(Pattern);
3327 if (Out.isInvalid())
3328 return true;
3329
Richard Smith9467be42014-06-06 17:33:35 +00003330 // FIXME: Can this happen? We should not try to expand the pack
3331 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003332 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003333 Out = getDerived().RebuildPackExpansion(
3334 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003335 if (Out.isInvalid())
3336 return true;
3337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor968f23a2011-01-03 19:31:53 +00003339 Outputs.push_back(Out.get());
3340 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Richard Smith9467be42014-06-06 17:33:35 +00003342 // If we're supposed to retain a pack expansion, do so by temporarily
3343 // forgetting the partially-substituted parameter pack.
3344 if (RetainExpansion) {
3345 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3346
3347 ExprResult Out = getDerived().TransformExpr(Pattern);
3348 if (Out.isInvalid())
3349 return true;
3350
3351 Out = getDerived().RebuildPackExpansion(
3352 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3353 if (Out.isInvalid())
3354 return true;
3355
3356 Outputs.push_back(Out.get());
3357 }
3358
Douglas Gregor968f23a2011-01-03 19:31:53 +00003359 continue;
3360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Richard Smithd59b8322012-12-19 01:39:02 +00003362 ExprResult Result =
3363 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3364 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003365 if (Result.isInvalid())
3366 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregora3efea12011-01-03 19:04:46 +00003368 if (Result.get() != Inputs[I] && ArgChanged)
3369 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003370
3371 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregora3efea12011-01-03 19:04:46 +00003374 return false;
3375}
3376
Richard Smith03a4aa32016-06-23 19:02:52 +00003377template <typename Derived>
3378Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3379 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3380 if (Var) {
3381 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3382 getDerived().TransformDefinition(Var->getLocation(), Var));
3383
3384 if (!ConditionVar)
3385 return Sema::ConditionError();
3386
3387 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3388 }
3389
3390 if (Expr) {
3391 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3392
3393 if (CondExpr.isInvalid())
3394 return Sema::ConditionError();
3395
3396 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3397 }
3398
3399 return Sema::ConditionResult();
3400}
3401
Douglas Gregora3efea12011-01-03 19:04:46 +00003402template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003403NestedNameSpecifierLoc
3404TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3405 NestedNameSpecifierLoc NNS,
3406 QualType ObjectType,
3407 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003408 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003409 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003410 Qualifier = Qualifier.getPrefix())
3411 Qualifiers.push_back(Qualifier);
3412
3413 CXXScopeSpec SS;
3414 while (!Qualifiers.empty()) {
3415 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3416 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregor14454802011-02-25 02:25:35 +00003418 switch (QNNS->getKind()) {
3419 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003420 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003421 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003422 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003423 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003424 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003425 FirstQualifierInScope, false))
3426 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor14454802011-02-25 02:25:35 +00003428 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor14454802011-02-25 02:25:35 +00003430 case NestedNameSpecifier::Namespace: {
3431 NamespaceDecl *NS
3432 = cast_or_null<NamespaceDecl>(
3433 getDerived().TransformDecl(
3434 Q.getLocalBeginLoc(),
3435 QNNS->getAsNamespace()));
3436 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3437 break;
3438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor14454802011-02-25 02:25:35 +00003440 case NestedNameSpecifier::NamespaceAlias: {
3441 NamespaceAliasDecl *Alias
3442 = cast_or_null<NamespaceAliasDecl>(
3443 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3444 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003445 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003446 Q.getLocalEndLoc());
3447 break;
3448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregor14454802011-02-25 02:25:35 +00003450 case NestedNameSpecifier::Global:
3451 // There is no meaningful transformation that one could perform on the
3452 // global scope.
3453 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3454 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Nikola Smiljanic67860242014-09-26 00:28:20 +00003456 case NestedNameSpecifier::Super: {
3457 CXXRecordDecl *RD =
3458 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3459 SourceLocation(), QNNS->getAsRecordDecl()));
3460 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3461 break;
3462 }
3463
Douglas Gregor14454802011-02-25 02:25:35 +00003464 case NestedNameSpecifier::TypeSpecWithTemplate:
3465 case NestedNameSpecifier::TypeSpec: {
3466 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3467 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003468
Douglas Gregor14454802011-02-25 02:25:35 +00003469 if (!TL)
3470 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003471
Douglas Gregor14454802011-02-25 02:25:35 +00003472 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003473 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003474 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003475 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003476 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003477 if (TL.getType()->isEnumeralType())
3478 SemaRef.Diag(TL.getBeginLoc(),
3479 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003480 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3481 Q.getLocalEndLoc());
3482 break;
3483 }
Richard Trieude756fb2011-05-07 01:36:37 +00003484 // If the nested-name-specifier is an invalid type def, don't emit an
3485 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003486 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3487 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003488 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003489 << TL.getType() << SS.getRange();
3490 }
Douglas Gregor14454802011-02-25 02:25:35 +00003491 return NestedNameSpecifierLoc();
3492 }
Douglas Gregore16af532011-02-28 18:50:33 +00003493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Douglas Gregore16af532011-02-28 18:50:33 +00003495 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003496 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003497 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
Douglas Gregor14454802011-02-25 02:25:35 +00003500 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003501 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003502 !getDerived().AlwaysRebuild())
3503 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003504
3505 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003506 // nested-name-specifier, do so.
3507 if (SS.location_size() == NNS.getDataLength() &&
3508 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3509 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3510
3511 // Allocate new nested-name-specifier location information.
3512 return SS.getWithLocInContext(SemaRef.Context);
3513}
3514
3515template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003516DeclarationNameInfo
3517TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003518::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003519 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003520 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003521 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003522
3523 switch (Name.getNameKind()) {
3524 case DeclarationName::Identifier:
3525 case DeclarationName::ObjCZeroArgSelector:
3526 case DeclarationName::ObjCOneArgSelector:
3527 case DeclarationName::ObjCMultiArgSelector:
3528 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003529 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003530 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003531 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorf816bd72009-09-03 22:13:48 +00003533 case DeclarationName::CXXConstructorName:
3534 case DeclarationName::CXXDestructorName:
3535 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003536 TypeSourceInfo *NewTInfo;
3537 CanQualType NewCanTy;
3538 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003539 NewTInfo = getDerived().TransformType(OldTInfo);
3540 if (!NewTInfo)
3541 return DeclarationNameInfo();
3542 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003543 }
3544 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003545 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003546 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003547 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003548 if (NewT.isNull())
3549 return DeclarationNameInfo();
3550 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3551 }
Mike Stump11289f42009-09-09 15:08:12 +00003552
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003553 DeclarationName NewName
3554 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3555 NewCanTy);
3556 DeclarationNameInfo NewNameInfo(NameInfo);
3557 NewNameInfo.setName(NewName);
3558 NewNameInfo.setNamedTypeInfo(NewTInfo);
3559 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003560 }
Mike Stump11289f42009-09-09 15:08:12 +00003561 }
3562
David Blaikie83d382b2011-09-23 05:06:16 +00003563 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003564}
3565
3566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003567TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003568TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3569 TemplateName Name,
3570 SourceLocation NameLoc,
3571 QualType ObjectType,
3572 NamedDecl *FirstQualifierInScope) {
3573 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3574 TemplateDecl *Template = QTN->getTemplateDecl();
3575 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor9db53502011-03-02 18:07:45 +00003577 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003578 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003579 Template));
3580 if (!TransTemplate)
3581 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003582
Douglas Gregor9db53502011-03-02 18:07:45 +00003583 if (!getDerived().AlwaysRebuild() &&
3584 SS.getScopeRep() == QTN->getQualifier() &&
3585 TransTemplate == Template)
3586 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregor9db53502011-03-02 18:07:45 +00003588 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3589 TransTemplate);
3590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregor9db53502011-03-02 18:07:45 +00003592 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3593 if (SS.getScopeRep()) {
3594 // These apply to the scope specifier, not the template.
3595 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003596 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003597 }
3598
Douglas Gregor9db53502011-03-02 18:07:45 +00003599 if (!getDerived().AlwaysRebuild() &&
3600 SS.getScopeRep() == DTN->getQualifier() &&
3601 ObjectType.isNull())
3602 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Douglas Gregor9db53502011-03-02 18:07:45 +00003604 if (DTN->isIdentifier()) {
3605 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003606 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003607 NameLoc,
3608 ObjectType,
3609 FirstQualifierInScope);
3610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor9db53502011-03-02 18:07:45 +00003612 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3613 ObjectType);
3614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor9db53502011-03-02 18:07:45 +00003616 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3617 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003618 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003619 Template));
3620 if (!TransTemplate)
3621 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor9db53502011-03-02 18:07:45 +00003623 if (!getDerived().AlwaysRebuild() &&
3624 TransTemplate == Template)
3625 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor9db53502011-03-02 18:07:45 +00003627 return TemplateName(TransTemplate);
3628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003629
Douglas Gregor9db53502011-03-02 18:07:45 +00003630 if (SubstTemplateTemplateParmPackStorage *SubstPack
3631 = Name.getAsSubstTemplateTemplateParmPack()) {
3632 TemplateTemplateParmDecl *TransParam
3633 = cast_or_null<TemplateTemplateParmDecl>(
3634 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3635 if (!TransParam)
3636 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor9db53502011-03-02 18:07:45 +00003638 if (!getDerived().AlwaysRebuild() &&
3639 TransParam == SubstPack->getParameterPack())
3640 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
3642 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003643 SubstPack->getArgumentPack());
3644 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor9db53502011-03-02 18:07:45 +00003646 // These should be getting filtered out before they reach the AST.
3647 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003648}
3649
3650template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003651void TreeTransform<Derived>::InventTemplateArgumentLoc(
3652 const TemplateArgument &Arg,
3653 TemplateArgumentLoc &Output) {
3654 SourceLocation Loc = getDerived().getBaseLocation();
3655 switch (Arg.getKind()) {
3656 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003657 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003658 break;
3659
3660 case TemplateArgument::Type:
3661 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003662 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
John McCall0ad16662009-10-29 08:12:44 +00003664 break;
3665
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003666 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003667 case TemplateArgument::TemplateExpansion: {
3668 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003669 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003670 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3671 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3672 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3673 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
Douglas Gregor9d802122011-03-02 17:09:35 +00003675 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003676 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003677 Builder.getWithLocInContext(SemaRef.Context),
3678 Loc);
3679 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003680 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003681 Builder.getWithLocInContext(SemaRef.Context),
3682 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003683
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003684 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003685 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003686
John McCall0ad16662009-10-29 08:12:44 +00003687 case TemplateArgument::Expression:
3688 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3689 break;
3690
3691 case TemplateArgument::Declaration:
3692 case TemplateArgument::Integral:
3693 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003694 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003695 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003696 break;
3697 }
3698}
3699
3700template<typename Derived>
3701bool TreeTransform<Derived>::TransformTemplateArgument(
3702 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003703 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003704 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003705 switch (Arg.getKind()) {
3706 case TemplateArgument::Null:
3707 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003708 case TemplateArgument::Pack:
3709 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003710 case TemplateArgument::NullPtr:
3711 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregore922c772009-08-04 22:27:00 +00003713 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003714 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003715 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003716 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003717
3718 DI = getDerived().TransformType(DI);
3719 if (!DI) return true;
3720
3721 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3722 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003725 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003726 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3727 if (QualifierLoc) {
3728 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3729 if (!QualifierLoc)
3730 return true;
3731 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Douglas Gregordf846d12011-03-02 18:46:51 +00003733 CXXScopeSpec SS;
3734 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003735 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003736 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3737 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003738 if (Template.isNull())
3739 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003740
Douglas Gregor9d802122011-03-02 17:09:35 +00003741 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003742 Input.getTemplateNameLoc());
3743 return false;
3744 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003745
3746 case TemplateArgument::TemplateExpansion:
3747 llvm_unreachable("Caller should expand pack expansions");
3748
Douglas Gregore922c772009-08-04 22:27:00 +00003749 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003750 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003751 EnterExpressionEvaluationContext Unevaluated(
3752 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003753
John McCall0ad16662009-10-29 08:12:44 +00003754 Expr *InputExpr = Input.getSourceExpression();
3755 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3756
Chris Lattnercdb591a2011-04-25 20:37:58 +00003757 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003758 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003759 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003760 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003761 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003762 }
Douglas Gregore922c772009-08-04 22:27:00 +00003763 }
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregore922c772009-08-04 22:27:00 +00003765 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003766 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003767}
3768
Douglas Gregorfe921a72010-12-20 23:36:19 +00003769/// \brief Iterator adaptor that invents template argument location information
3770/// for each of the template arguments in its underlying iterator.
3771template<typename Derived, typename InputIterator>
3772class TemplateArgumentLocInventIterator {
3773 TreeTransform<Derived> &Self;
3774 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003775
Douglas Gregorfe921a72010-12-20 23:36:19 +00003776public:
3777 typedef TemplateArgumentLoc value_type;
3778 typedef TemplateArgumentLoc reference;
3779 typedef typename std::iterator_traits<InputIterator>::difference_type
3780 difference_type;
3781 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregorfe921a72010-12-20 23:36:19 +00003783 class pointer {
3784 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003785
Douglas Gregorfe921a72010-12-20 23:36:19 +00003786 public:
3787 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003788
Douglas Gregorfe921a72010-12-20 23:36:19 +00003789 const TemplateArgumentLoc *operator->() const { return &Arg; }
3790 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003792 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003793
Douglas Gregorfe921a72010-12-20 23:36:19 +00003794 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3795 InputIterator Iter)
3796 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
Douglas Gregorfe921a72010-12-20 23:36:19 +00003798 TemplateArgumentLocInventIterator &operator++() {
3799 ++Iter;
3800 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003802
Douglas Gregorfe921a72010-12-20 23:36:19 +00003803 TemplateArgumentLocInventIterator operator++(int) {
3804 TemplateArgumentLocInventIterator Old(*this);
3805 ++(*this);
3806 return Old;
3807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003808
Douglas Gregorfe921a72010-12-20 23:36:19 +00003809 reference operator*() const {
3810 TemplateArgumentLoc Result;
3811 Self.InventTemplateArgumentLoc(*Iter, Result);
3812 return Result;
3813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregorfe921a72010-12-20 23:36:19 +00003815 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregorfe921a72010-12-20 23:36:19 +00003817 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3818 const TemplateArgumentLocInventIterator &Y) {
3819 return X.Iter == Y.Iter;
3820 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003821
Douglas Gregorfe921a72010-12-20 23:36:19 +00003822 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3823 const TemplateArgumentLocInventIterator &Y) {
3824 return X.Iter != Y.Iter;
3825 }
3826};
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Douglas Gregor42cafa82010-12-20 17:42:22 +00003828template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003829template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003830bool TreeTransform<Derived>::TransformTemplateArguments(
3831 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3832 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003833 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003834 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003835 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003837 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3838 // Unpack argument packs, which we translate them into separate
3839 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003840 // FIXME: We could do much better if we could guarantee that the
3841 // TemplateArgumentLocInfo for the pack expansion would be usable for
3842 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003843 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003844 TemplateArgument::pack_iterator>
3845 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003847 In.getArgument().pack_begin()),
3848 PackLocIterator(*this,
3849 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003850 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003851 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003852
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003853 continue;
3854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003856 if (In.getArgument().isPackExpansion()) {
3857 // We have a pack expansion, for which we will be substituting into
3858 // the pattern.
3859 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003860 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003861 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003862 = getSema().getTemplateArgumentPackExpansionPattern(
3863 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
Chris Lattner01cf8db2011-07-20 06:58:45 +00003865 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003866 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3867 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003868
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003869 // Determine whether the set of unexpanded parameter packs can and should
3870 // be expanded.
3871 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003872 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003873 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003874 if (getDerived().TryExpandParameterPacks(Ellipsis,
3875 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003876 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003877 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003878 RetainExpansion,
3879 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003880 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003882 if (!Expand) {
3883 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003884 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003885 // expansion.
3886 TemplateArgumentLoc OutPattern;
3887 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003888 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003889 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003891 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3892 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003893 if (Out.getArgument().isNull())
3894 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003896 Outputs.addArgument(Out);
3897 continue;
3898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003900 // The transform has determined that we should perform an elementwise
3901 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003902 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003903 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3904
Richard Smithd784e682015-09-23 21:41:42 +00003905 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003906 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003907
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003908 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003909 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3910 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003911 if (Out.getArgument().isNull())
3912 return true;
3913 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003915 Outputs.addArgument(Out);
3916 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003917
Douglas Gregor48d24112011-01-10 20:53:55 +00003918 // If we're supposed to retain a pack expansion, do so by temporarily
3919 // forgetting the partially-substituted parameter pack.
3920 if (RetainExpansion) {
3921 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003922
Richard Smithd784e682015-09-23 21:41:42 +00003923 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003924 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003925
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003926 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3927 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003928 if (Out.getArgument().isNull())
3929 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
Douglas Gregor48d24112011-01-10 20:53:55 +00003931 Outputs.addArgument(Out);
3932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003934 continue;
3935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003936
3937 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003938 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003939 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003940
Douglas Gregor42cafa82010-12-20 17:42:22 +00003941 Outputs.addArgument(Out);
3942 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003943
Douglas Gregor42cafa82010-12-20 17:42:22 +00003944 return false;
3945
3946}
3947
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948//===----------------------------------------------------------------------===//
3949// Type transformation
3950//===----------------------------------------------------------------------===//
3951
3952template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003953QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954 if (getDerived().AlreadyTransformed(T))
3955 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003956
John McCall550e0c22009-10-21 00:40:46 +00003957 // Temporary workaround. All of these transformations should
3958 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003959 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3960 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
John McCall31f82722010-11-12 08:19:04 +00003962 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003963
John McCall550e0c22009-10-21 00:40:46 +00003964 if (!NewDI)
3965 return QualType();
3966
3967 return NewDI->getType();
3968}
3969
3970template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003971TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003972 // Refine the base location to the type's location.
3973 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3974 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003975 if (getDerived().AlreadyTransformed(DI->getType()))
3976 return DI;
3977
3978 TypeLocBuilder TLB;
3979
3980 TypeLoc TL = DI->getTypeLoc();
3981 TLB.reserve(TL.getFullDataSize());
3982
John McCall31f82722010-11-12 08:19:04 +00003983 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003984 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003985 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003986
John McCallbcd03502009-12-07 02:54:59 +00003987 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003988}
3989
3990template<typename Derived>
3991QualType
John McCall31f82722010-11-12 08:19:04 +00003992TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003993 switch (T.getTypeLocClass()) {
3994#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003995#define TYPELOC(CLASS, PARENT) \
3996 case TypeLoc::CLASS: \
3997 return getDerived().Transform##CLASS##Type(TLB, \
3998 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003999#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000 }
Mike Stump11289f42009-09-09 15:08:12 +00004001
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004002 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004003}
4004
4005/// FIXME: By default, this routine adds type qualifiers only to types
4006/// that can have qualifiers, and silently suppresses those qualifiers
4007/// that are not permitted (e.g., qualifiers on reference or function
4008/// types). This is the right thing for template instantiation, but
4009/// probably not for other clients.
4010template<typename Derived>
4011QualType
4012TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004013 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004014 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004015
John McCall31f82722010-11-12 08:19:04 +00004016 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004017 if (Result.isNull())
4018 return QualType();
4019
4020 // Silently suppress qualifiers if the result type can't be qualified.
4021 // FIXME: this is the right thing for template instantiation, but
4022 // probably not for other clients.
4023 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004024 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004025
John McCall31168b02011-06-15 23:02:42 +00004026 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004027 // resulting type.
4028 if (Quals.hasObjCLifetime()) {
4029 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4030 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004031 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004032 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004033 // A lifetime qualifier applied to a substituted template parameter
4034 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004035 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004036 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004037 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4038 QualType Replacement = SubstTypeParam->getReplacementType();
4039 Qualifiers Qs = Replacement.getQualifiers();
4040 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004041 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004042 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4043 Qs);
4044 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004045 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004046 Replacement);
4047 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004048 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4049 // 'auto' types behave the same way as template parameters.
4050 QualType Deduced = AutoTy->getDeducedType();
4051 Qualifiers Qs = Deduced.getQualifiers();
4052 Qs.removeObjCLifetime();
4053 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4054 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004055 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004056 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004057 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004058 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004059 // Otherwise, complain about the addition of a qualifier to an
4060 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004061 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004062 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004063 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
Douglas Gregore46db902011-06-17 22:11:49 +00004065 Quals.removeObjCLifetime();
4066 }
4067 }
4068 }
John McCallcb0f89a2010-06-05 06:41:15 +00004069 if (!Quals.empty()) {
4070 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004071 // BuildQualifiedType might not add qualifiers if they are invalid.
4072 if (Result.hasLocalQualifiers())
4073 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004074 // No location information to preserve.
4075 }
John McCall550e0c22009-10-21 00:40:46 +00004076
4077 return Result;
4078}
4079
Douglas Gregor14454802011-02-25 02:25:35 +00004080template<typename Derived>
4081TypeLoc
4082TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4083 QualType ObjectType,
4084 NamedDecl *UnqualLookup,
4085 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004086 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004087 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004089 TypeSourceInfo *TSI =
4090 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4091 if (TSI)
4092 return TSI->getTypeLoc();
4093 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004094}
4095
Douglas Gregor579c15f2011-03-02 18:32:08 +00004096template<typename Derived>
4097TypeSourceInfo *
4098TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4099 QualType ObjectType,
4100 NamedDecl *UnqualLookup,
4101 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004102 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004103 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004104
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004105 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4106 UnqualLookup, SS);
4107}
4108
4109template <typename Derived>
4110TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4111 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4112 CXXScopeSpec &SS) {
4113 QualType T = TL.getType();
4114 assert(!getDerived().AlreadyTransformed(T));
4115
Douglas Gregor579c15f2011-03-02 18:32:08 +00004116 TypeLocBuilder TLB;
4117 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004118
Douglas Gregor579c15f2011-03-02 18:32:08 +00004119 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004120 TemplateSpecializationTypeLoc SpecTL =
4121 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Douglas Gregor579c15f2011-03-02 18:32:08 +00004123 TemplateName Template
4124 = getDerived().TransformTemplateName(SS,
4125 SpecTL.getTypePtr()->getTemplateName(),
4126 SpecTL.getTemplateNameLoc(),
4127 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004128 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004129 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004130
4131 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004132 Template);
4133 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004134 DependentTemplateSpecializationTypeLoc SpecTL =
4135 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004136
Douglas Gregor579c15f2011-03-02 18:32:08 +00004137 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004138 = getDerived().RebuildTemplateName(SS,
4139 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004140 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004141 ObjectType, UnqualLookup);
4142 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004143 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004144
4145 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004146 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004147 Template,
4148 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004149 } else {
4150 // Nothing special needs to be done for these.
4151 Result = getDerived().TransformType(TLB, TL);
4152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004153
4154 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004155 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004156
Douglas Gregor579c15f2011-03-02 18:32:08 +00004157 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4158}
4159
John McCall550e0c22009-10-21 00:40:46 +00004160template <class TyLoc> static inline
4161QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4162 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4163 NewT.setNameLoc(T.getNameLoc());
4164 return T.getType();
4165}
4166
John McCall550e0c22009-10-21 00:40:46 +00004167template<typename Derived>
4168QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004169 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004170 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4171 NewT.setBuiltinLoc(T.getBuiltinLoc());
4172 if (T.needsExtraLocalData())
4173 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4174 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175}
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004178QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004180 // FIXME: recurse?
4181 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182}
Mike Stump11289f42009-09-09 15:08:12 +00004183
Reid Kleckner0503a872013-12-05 01:23:43 +00004184template <typename Derived>
4185QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4186 AdjustedTypeLoc TL) {
4187 // Adjustments applied during transformation are handled elsewhere.
4188 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4189}
4190
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004192QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4193 DecayedTypeLoc TL) {
4194 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4195 if (OriginalType.isNull())
4196 return QualType();
4197
4198 QualType Result = TL.getType();
4199 if (getDerived().AlwaysRebuild() ||
4200 OriginalType != TL.getOriginalLoc().getType())
4201 Result = SemaRef.Context.getDecayedType(OriginalType);
4202 TLB.push<DecayedTypeLoc>(Result);
4203 // Nothing to set for DecayedTypeLoc.
4204 return Result;
4205}
4206
4207template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004208QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004209 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004210 QualType PointeeType
4211 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004212 if (PointeeType.isNull())
4213 return QualType();
4214
4215 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004216 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004217 // A dependent pointer type 'T *' has is being transformed such
4218 // that an Objective-C class type is being replaced for 'T'. The
4219 // resulting pointer type is an ObjCObjectPointerType, not a
4220 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004221 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004222
John McCall8b07ec22010-05-15 11:32:37 +00004223 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4224 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004225 return Result;
4226 }
John McCall31f82722010-11-12 08:19:04 +00004227
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004228 if (getDerived().AlwaysRebuild() ||
4229 PointeeType != TL.getPointeeLoc().getType()) {
4230 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4231 if (Result.isNull())
4232 return QualType();
4233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004234
John McCall31168b02011-06-15 23:02:42 +00004235 // Objective-C ARC can add lifetime qualifiers to the type that we're
4236 // pointing to.
4237 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004238
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004239 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4240 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004241 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242}
Mike Stump11289f42009-09-09 15:08:12 +00004243
4244template<typename Derived>
4245QualType
John McCall550e0c22009-10-21 00:40:46 +00004246TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004247 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004248 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004249 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4250 if (PointeeType.isNull())
4251 return QualType();
4252
4253 QualType Result = TL.getType();
4254 if (getDerived().AlwaysRebuild() ||
4255 PointeeType != TL.getPointeeLoc().getType()) {
4256 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004257 TL.getSigilLoc());
4258 if (Result.isNull())
4259 return QualType();
4260 }
4261
Douglas Gregor049211a2010-04-22 16:50:51 +00004262 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004263 NewT.setSigilLoc(TL.getSigilLoc());
4264 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265}
4266
John McCall70dd5f62009-10-30 00:06:24 +00004267/// Transforms a reference type. Note that somewhat paradoxically we
4268/// don't care whether the type itself is an l-value type or an r-value
4269/// type; we only care if the type was *written* as an l-value type
4270/// or an r-value type.
4271template<typename Derived>
4272QualType
4273TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004274 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004275 const ReferenceType *T = TL.getTypePtr();
4276
4277 // Note that this works with the pointee-as-written.
4278 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4279 if (PointeeType.isNull())
4280 return QualType();
4281
4282 QualType Result = TL.getType();
4283 if (getDerived().AlwaysRebuild() ||
4284 PointeeType != T->getPointeeTypeAsWritten()) {
4285 Result = getDerived().RebuildReferenceType(PointeeType,
4286 T->isSpelledAsLValue(),
4287 TL.getSigilLoc());
4288 if (Result.isNull())
4289 return QualType();
4290 }
4291
John McCall31168b02011-06-15 23:02:42 +00004292 // Objective-C ARC can add lifetime qualifiers to the type that we're
4293 // referring to.
4294 TLB.TypeWasModifiedSafely(
4295 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4296
John McCall70dd5f62009-10-30 00:06:24 +00004297 // r-value references can be rebuilt as l-value references.
4298 ReferenceTypeLoc NewTL;
4299 if (isa<LValueReferenceType>(Result))
4300 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4301 else
4302 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4303 NewTL.setSigilLoc(TL.getSigilLoc());
4304
4305 return Result;
4306}
4307
Mike Stump11289f42009-09-09 15:08:12 +00004308template<typename Derived>
4309QualType
John McCall550e0c22009-10-21 00:40:46 +00004310TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004311 LValueReferenceTypeLoc TL) {
4312 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004313}
4314
Mike Stump11289f42009-09-09 15:08:12 +00004315template<typename Derived>
4316QualType
John McCall550e0c22009-10-21 00:40:46 +00004317TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004318 RValueReferenceTypeLoc TL) {
4319 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004320}
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregord6ff3322009-08-04 16:50:30 +00004322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004323QualType
John McCall550e0c22009-10-21 00:40:46 +00004324TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004325 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004326 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004327 if (PointeeType.isNull())
4328 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004329
Abramo Bagnara509357842011-03-05 14:42:21 +00004330 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004331 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004332 if (OldClsTInfo) {
4333 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4334 if (!NewClsTInfo)
4335 return QualType();
4336 }
4337
4338 const MemberPointerType *T = TL.getTypePtr();
4339 QualType OldClsType = QualType(T->getClass(), 0);
4340 QualType NewClsType;
4341 if (NewClsTInfo)
4342 NewClsType = NewClsTInfo->getType();
4343 else {
4344 NewClsType = getDerived().TransformType(OldClsType);
4345 if (NewClsType.isNull())
4346 return QualType();
4347 }
Mike Stump11289f42009-09-09 15:08:12 +00004348
John McCall550e0c22009-10-21 00:40:46 +00004349 QualType Result = TL.getType();
4350 if (getDerived().AlwaysRebuild() ||
4351 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004352 NewClsType != OldClsType) {
4353 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004354 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004355 if (Result.isNull())
4356 return QualType();
4357 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004358
Reid Kleckner0503a872013-12-05 01:23:43 +00004359 // If we had to adjust the pointee type when building a member pointer, make
4360 // sure to push TypeLoc info for it.
4361 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4362 if (MPT && PointeeType != MPT->getPointeeType()) {
4363 assert(isa<AdjustedType>(MPT->getPointeeType()));
4364 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4365 }
4366
John McCall550e0c22009-10-21 00:40:46 +00004367 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4368 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004369 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004370
4371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004372}
4373
Mike Stump11289f42009-09-09 15:08:12 +00004374template<typename Derived>
4375QualType
John McCall550e0c22009-10-21 00:40:46 +00004376TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004377 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004378 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004379 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004380 if (ElementType.isNull())
4381 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004382
John McCall550e0c22009-10-21 00:40:46 +00004383 QualType Result = TL.getType();
4384 if (getDerived().AlwaysRebuild() ||
4385 ElementType != T->getElementType()) {
4386 Result = getDerived().RebuildConstantArrayType(ElementType,
4387 T->getSizeModifier(),
4388 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004389 T->getIndexTypeCVRQualifiers(),
4390 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004391 if (Result.isNull())
4392 return QualType();
4393 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004394
4395 // We might have either a ConstantArrayType or a VariableArrayType now:
4396 // a ConstantArrayType is allowed to have an element type which is a
4397 // VariableArrayType if the type is dependent. Fortunately, all array
4398 // types have the same location layout.
4399 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004400 NewTL.setLBracketLoc(TL.getLBracketLoc());
4401 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004402
John McCall550e0c22009-10-21 00:40:46 +00004403 Expr *Size = TL.getSizeExpr();
4404 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004405 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4406 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004407 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4408 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004409 }
4410 NewTL.setSizeExpr(Size);
4411
4412 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004413}
Mike Stump11289f42009-09-09 15:08:12 +00004414
Douglas Gregord6ff3322009-08-04 16:50:30 +00004415template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004416QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004417 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004418 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004419 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004420 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421 if (ElementType.isNull())
4422 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004423
John McCall550e0c22009-10-21 00:40:46 +00004424 QualType Result = TL.getType();
4425 if (getDerived().AlwaysRebuild() ||
4426 ElementType != T->getElementType()) {
4427 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004428 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004429 T->getIndexTypeCVRQualifiers(),
4430 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004431 if (Result.isNull())
4432 return QualType();
4433 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004434
John McCall550e0c22009-10-21 00:40:46 +00004435 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4436 NewTL.setLBracketLoc(TL.getLBracketLoc());
4437 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004438 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004439
4440 return Result;
4441}
4442
4443template<typename Derived>
4444QualType
4445TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004446 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004447 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004448 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4449 if (ElementType.isNull())
4450 return QualType();
4451
John McCalldadc5752010-08-24 06:29:42 +00004452 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004453 = getDerived().TransformExpr(T->getSizeExpr());
4454 if (SizeResult.isInvalid())
4455 return QualType();
4456
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004457 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004458
4459 QualType Result = TL.getType();
4460 if (getDerived().AlwaysRebuild() ||
4461 ElementType != T->getElementType() ||
4462 Size != T->getSizeExpr()) {
4463 Result = getDerived().RebuildVariableArrayType(ElementType,
4464 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004465 Size,
John McCall550e0c22009-10-21 00:40:46 +00004466 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004467 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004468 if (Result.isNull())
4469 return QualType();
4470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004471
Serge Pavlov774c6d02014-02-06 03:49:11 +00004472 // We might have constant size array now, but fortunately it has the same
4473 // location layout.
4474 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004475 NewTL.setLBracketLoc(TL.getLBracketLoc());
4476 NewTL.setRBracketLoc(TL.getRBracketLoc());
4477 NewTL.setSizeExpr(Size);
4478
4479 return Result;
4480}
4481
4482template<typename Derived>
4483QualType
4484TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004485 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004486 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004487 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4488 if (ElementType.isNull())
4489 return QualType();
4490
Richard Smith764d2fe2011-12-20 02:08:33 +00004491 // Array bounds are constant expressions.
4492 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4493 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004494
John McCall33ddac02011-01-19 10:06:00 +00004495 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4496 Expr *origSize = TL.getSizeExpr();
4497 if (!origSize) origSize = T->getSizeExpr();
4498
4499 ExprResult sizeResult
4500 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004501 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004502 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004503 return QualType();
4504
John McCall33ddac02011-01-19 10:06:00 +00004505 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004506
4507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004510 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004511 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4512 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004513 size,
John McCall550e0c22009-10-21 00:40:46 +00004514 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004515 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004516 if (Result.isNull())
4517 return QualType();
4518 }
John McCall550e0c22009-10-21 00:40:46 +00004519
4520 // We might have any sort of array type now, but fortunately they
4521 // all have the same location layout.
4522 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4523 NewTL.setLBracketLoc(TL.getLBracketLoc());
4524 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004525 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004526
4527 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528}
Mike Stump11289f42009-09-09 15:08:12 +00004529
4530template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004532 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004534 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004535
4536 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004537 QualType ElementType = getDerived().TransformType(T->getElementType());
4538 if (ElementType.isNull())
4539 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004540
Richard Smith764d2fe2011-12-20 02:08:33 +00004541 // Vector sizes are constant expressions.
4542 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4543 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004544
John McCalldadc5752010-08-24 06:29:42 +00004545 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004546 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547 if (Size.isInvalid())
4548 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004549
John McCall550e0c22009-10-21 00:40:46 +00004550 QualType Result = TL.getType();
4551 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004552 ElementType != T->getElementType() ||
4553 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004554 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004555 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004556 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004557 if (Result.isNull())
4558 return QualType();
4559 }
John McCall550e0c22009-10-21 00:40:46 +00004560
4561 // Result might be dependent or not.
4562 if (isa<DependentSizedExtVectorType>(Result)) {
4563 DependentSizedExtVectorTypeLoc NewTL
4564 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4565 NewTL.setNameLoc(TL.getNameLoc());
4566 } else {
4567 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4568 NewTL.setNameLoc(TL.getNameLoc());
4569 }
4570
4571 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572}
Mike Stump11289f42009-09-09 15:08:12 +00004573
4574template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004575QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004576 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004577 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578 QualType ElementType = getDerived().TransformType(T->getElementType());
4579 if (ElementType.isNull())
4580 return QualType();
4581
John McCall550e0c22009-10-21 00:40:46 +00004582 QualType Result = TL.getType();
4583 if (getDerived().AlwaysRebuild() ||
4584 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004585 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004586 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004587 if (Result.isNull())
4588 return QualType();
4589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004590
John McCall550e0c22009-10-21 00:40:46 +00004591 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4592 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004593
John McCall550e0c22009-10-21 00:40:46 +00004594 return Result;
4595}
4596
4597template<typename Derived>
4598QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004599 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004600 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004601 QualType ElementType = getDerived().TransformType(T->getElementType());
4602 if (ElementType.isNull())
4603 return QualType();
4604
4605 QualType Result = TL.getType();
4606 if (getDerived().AlwaysRebuild() ||
4607 ElementType != T->getElementType()) {
4608 Result = getDerived().RebuildExtVectorType(ElementType,
4609 T->getNumElements(),
4610 /*FIXME*/ SourceLocation());
4611 if (Result.isNull())
4612 return QualType();
4613 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004614
John McCall550e0c22009-10-21 00:40:46 +00004615 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4616 NewTL.setNameLoc(TL.getNameLoc());
4617
4618 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004619}
Mike Stump11289f42009-09-09 15:08:12 +00004620
David Blaikie05785d12013-02-20 22:23:23 +00004621template <typename Derived>
4622ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4623 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4624 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004625 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004626 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004627
Douglas Gregor715e4612011-01-14 22:40:04 +00004628 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004629 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004630 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004631 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004632 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004633
Douglas Gregor715e4612011-01-14 22:40:04 +00004634 TypeLocBuilder TLB;
4635 TypeLoc NewTL = OldDI->getTypeLoc();
4636 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004637
4638 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004639 OldExpansionTL.getPatternLoc());
4640 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004641 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004642
4643 Result = RebuildPackExpansionType(Result,
4644 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004645 OldExpansionTL.getEllipsisLoc(),
4646 NumExpansions);
4647 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004648 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004649
Douglas Gregor715e4612011-01-14 22:40:04 +00004650 PackExpansionTypeLoc NewExpansionTL
4651 = TLB.push<PackExpansionTypeLoc>(Result);
4652 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4653 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4654 } else
4655 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004656 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004657 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004658
John McCall8fb0d9d2011-05-01 22:35:37 +00004659 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004660 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004661
4662 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4663 OldParm->getDeclContext(),
4664 OldParm->getInnerLocStart(),
4665 OldParm->getLocation(),
4666 OldParm->getIdentifier(),
4667 NewDI->getType(),
4668 NewDI,
4669 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004670 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004671 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4672 OldParm->getFunctionScopeIndex() + indexAdjustment);
4673 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004674}
4675
David Majnemer59f77922016-06-24 04:05:48 +00004676template <typename Derived>
4677bool TreeTransform<Derived>::TransformFunctionTypeParams(
4678 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4679 const QualType *ParamTypes,
4680 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4681 SmallVectorImpl<QualType> &OutParamTypes,
4682 SmallVectorImpl<ParmVarDecl *> *PVars,
4683 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004684 int indexAdjustment = 0;
4685
David Majnemer59f77922016-06-24 04:05:48 +00004686 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004687 for (unsigned i = 0; i != NumParams; ++i) {
4688 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004689 assert(OldParm->getFunctionScopeIndex() == i);
4690
David Blaikie05785d12013-02-20 22:23:23 +00004691 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004692 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004693 if (OldParm->isParameterPack()) {
4694 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004695 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004696
Douglas Gregor5499af42011-01-05 23:12:31 +00004697 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004698 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004699 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004700 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4701 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004702 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4703
Douglas Gregor5499af42011-01-05 23:12:31 +00004704 // Determine whether we should expand the parameter packs.
4705 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004706 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004707 Optional<unsigned> OrigNumExpansions =
4708 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004709 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004710 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4711 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004712 Unexpanded,
4713 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004714 RetainExpansion,
4715 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004716 return true;
4717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004718
Douglas Gregor5499af42011-01-05 23:12:31 +00004719 if (ShouldExpand) {
4720 // Expand the function parameter pack into multiple, separate
4721 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004722 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004723 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004724 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004725 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004726 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004727 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004728 OrigNumExpansions,
4729 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004730 if (!NewParm)
4731 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004732
John McCallc8e321d2016-03-01 02:09:25 +00004733 if (ParamInfos)
4734 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004735 OutParamTypes.push_back(NewParm->getType());
4736 if (PVars)
4737 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004738 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004739
4740 // If we're supposed to retain a pack expansion, do so by temporarily
4741 // forgetting the partially-substituted parameter pack.
4742 if (RetainExpansion) {
4743 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004744 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004745 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004746 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004747 OrigNumExpansions,
4748 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004749 if (!NewParm)
4750 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004751
John McCallc8e321d2016-03-01 02:09:25 +00004752 if (ParamInfos)
4753 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004754 OutParamTypes.push_back(NewParm->getType());
4755 if (PVars)
4756 PVars->push_back(NewParm);
4757 }
4758
John McCall8fb0d9d2011-05-01 22:35:37 +00004759 // The next parameter should have the same adjustment as the
4760 // last thing we pushed, but we post-incremented indexAdjustment
4761 // on every push. Also, if we push nothing, the adjustment should
4762 // go down by one.
4763 indexAdjustment--;
4764
Douglas Gregor5499af42011-01-05 23:12:31 +00004765 // We're done with the pack expansion.
4766 continue;
4767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004768
4769 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004770 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004771 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4772 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004773 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004774 NumExpansions,
4775 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004776 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004777 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004778 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004779 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004780
John McCall58f10c32010-03-11 09:03:00 +00004781 if (!NewParm)
4782 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004783
John McCallc8e321d2016-03-01 02:09:25 +00004784 if (ParamInfos)
4785 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004786 OutParamTypes.push_back(NewParm->getType());
4787 if (PVars)
4788 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004789 continue;
4790 }
John McCall58f10c32010-03-11 09:03:00 +00004791
4792 // Deal with the possibility that we don't have a parameter
4793 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004794 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004795 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004796 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004797 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004798 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004799 = dyn_cast<PackExpansionType>(OldType)) {
4800 // We have a function parameter pack that may need to be expanded.
4801 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004802 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004803 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
Douglas Gregor5499af42011-01-05 23:12:31 +00004805 // Determine whether we should expand the parameter packs.
4806 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004807 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004808 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004809 Unexpanded,
4810 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004811 RetainExpansion,
4812 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004813 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004815
Douglas Gregor5499af42011-01-05 23:12:31 +00004816 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004817 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004818 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004819 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004820 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4821 QualType NewType = getDerived().TransformType(Pattern);
4822 if (NewType.isNull())
4823 return true;
John McCall58f10c32010-03-11 09:03:00 +00004824
John McCallc8e321d2016-03-01 02:09:25 +00004825 if (ParamInfos)
4826 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004827 OutParamTypes.push_back(NewType);
4828 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004829 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregor5499af42011-01-05 23:12:31 +00004832 // We're done with the pack expansion.
4833 continue;
4834 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004835
Douglas Gregor48d24112011-01-10 20:53:55 +00004836 // If we're supposed to retain a pack expansion, do so by temporarily
4837 // forgetting the partially-substituted parameter pack.
4838 if (RetainExpansion) {
4839 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4840 QualType NewType = getDerived().TransformType(Pattern);
4841 if (NewType.isNull())
4842 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004843
John McCallc8e321d2016-03-01 02:09:25 +00004844 if (ParamInfos)
4845 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004846 OutParamTypes.push_back(NewType);
4847 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004848 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004849 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004850
Chad Rosier1dcde962012-08-08 18:46:20 +00004851 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004852 // expansion.
4853 OldType = Expansion->getPattern();
4854 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004855 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4856 NewType = getDerived().TransformType(OldType);
4857 } else {
4858 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004860
Douglas Gregor5499af42011-01-05 23:12:31 +00004861 if (NewType.isNull())
4862 return true;
4863
4864 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004865 NewType = getSema().Context.getPackExpansionType(NewType,
4866 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004867
John McCallc8e321d2016-03-01 02:09:25 +00004868 if (ParamInfos)
4869 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004870 OutParamTypes.push_back(NewType);
4871 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004872 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004873 }
4874
John McCall8fb0d9d2011-05-01 22:35:37 +00004875#ifndef NDEBUG
4876 if (PVars) {
4877 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4878 if (ParmVarDecl *parm = (*PVars)[i])
4879 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004880 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004881#endif
4882
4883 return false;
4884}
John McCall58f10c32010-03-11 09:03:00 +00004885
4886template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004887QualType
John McCall550e0c22009-10-21 00:40:46 +00004888TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004889 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004890 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004891 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004892 return getDerived().TransformFunctionProtoType(
4893 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004894 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4895 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4896 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004897 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004898}
4899
Richard Smith2e321552014-11-12 02:00:47 +00004900template<typename Derived> template<typename Fn>
4901QualType TreeTransform<Derived>::TransformFunctionProtoType(
4902 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4903 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004904
Douglas Gregor4afc2362010-08-31 00:26:14 +00004905 // Transform the parameters and return type.
4906 //
Richard Smithf623c962012-04-17 00:58:00 +00004907 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004908 // When the function has a trailing return type, we instantiate the
4909 // parameters before the return type, since the return type can then refer
4910 // to the parameters themselves (via decltype, sizeof, etc.).
4911 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004912 SmallVector<QualType, 4> ParamTypes;
4913 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004914 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004915 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004916
Douglas Gregor7fb25412010-10-01 18:44:50 +00004917 QualType ResultType;
4918
Richard Smith1226c602012-08-14 22:51:13 +00004919 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004920 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004921 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004922 TL.getTypePtr()->param_type_begin(),
4923 T->getExtParameterInfosOrNull(),
4924 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004925 return QualType();
4926
Douglas Gregor3024f072012-04-16 07:05:22 +00004927 {
4928 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004929 // If a declaration declares a member function or member function
4930 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004931 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004932 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004933 // declarator.
4934 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004935
Alp Toker42a16a62014-01-25 23:51:36 +00004936 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004937 if (ResultType.isNull())
4938 return QualType();
4939 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004940 }
4941 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004942 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004943 if (ResultType.isNull())
4944 return QualType();
4945
Alp Toker9cacbab2014-01-20 20:26:09 +00004946 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004947 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004948 TL.getTypePtr()->param_type_begin(),
4949 T->getExtParameterInfosOrNull(),
4950 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004951 return QualType();
4952 }
4953
Richard Smith2e321552014-11-12 02:00:47 +00004954 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4955
4956 bool EPIChanged = false;
4957 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4958 return QualType();
4959
John McCallc8e321d2016-03-01 02:09:25 +00004960 // Handle extended parameter information.
4961 if (auto NewExtParamInfos =
4962 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4963 if (!EPI.ExtParameterInfos ||
4964 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4965 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4966 EPIChanged = true;
4967 }
4968 EPI.ExtParameterInfos = NewExtParamInfos;
4969 } else if (EPI.ExtParameterInfos) {
4970 EPIChanged = true;
4971 EPI.ExtParameterInfos = nullptr;
4972 }
Richard Smithf623c962012-04-17 00:58:00 +00004973
John McCall550e0c22009-10-21 00:40:46 +00004974 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004975 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004976 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004977 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004978 if (Result.isNull())
4979 return QualType();
4980 }
Mike Stump11289f42009-09-09 15:08:12 +00004981
John McCall550e0c22009-10-21 00:40:46 +00004982 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004983 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004984 NewTL.setLParenLoc(TL.getLParenLoc());
4985 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004986 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004987 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4988 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004989
4990 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004991}
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregord6ff3322009-08-04 16:50:30 +00004993template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004994bool TreeTransform<Derived>::TransformExceptionSpec(
4995 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4996 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4997 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4998
4999 // Instantiate a dynamic noexcept expression, if any.
5000 if (ESI.Type == EST_ComputedNoexcept) {
5001 EnterExpressionEvaluationContext Unevaluated(getSema(),
5002 Sema::ConstantEvaluated);
5003 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5004 if (NoexceptExpr.isInvalid())
5005 return true;
5006
Richard Smith03a4aa32016-06-23 19:02:52 +00005007 // FIXME: This is bogus, a noexcept expression is not a condition.
5008 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005009 if (NoexceptExpr.isInvalid())
5010 return true;
5011
5012 if (!NoexceptExpr.get()->isValueDependent()) {
5013 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5014 NoexceptExpr.get(), nullptr,
5015 diag::err_noexcept_needs_constant_expression,
5016 /*AllowFold*/false);
5017 if (NoexceptExpr.isInvalid())
5018 return true;
5019 }
5020
5021 if (ESI.NoexceptExpr != NoexceptExpr.get())
5022 Changed = true;
5023 ESI.NoexceptExpr = NoexceptExpr.get();
5024 }
5025
5026 if (ESI.Type != EST_Dynamic)
5027 return false;
5028
5029 // Instantiate a dynamic exception specification's type.
5030 for (QualType T : ESI.Exceptions) {
5031 if (const PackExpansionType *PackExpansion =
5032 T->getAs<PackExpansionType>()) {
5033 Changed = true;
5034
5035 // We have a pack expansion. Instantiate it.
5036 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5037 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5038 Unexpanded);
5039 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5040
5041 // Determine whether the set of unexpanded parameter packs can and
5042 // should
5043 // be expanded.
5044 bool Expand = false;
5045 bool RetainExpansion = false;
5046 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5047 // FIXME: Track the location of the ellipsis (and track source location
5048 // information for the types in the exception specification in general).
5049 if (getDerived().TryExpandParameterPacks(
5050 Loc, SourceRange(), Unexpanded, Expand,
5051 RetainExpansion, NumExpansions))
5052 return true;
5053
5054 if (!Expand) {
5055 // We can't expand this pack expansion into separate arguments yet;
5056 // just substitute into the pattern and create a new pack expansion
5057 // type.
5058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5059 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5060 if (U.isNull())
5061 return true;
5062
5063 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5064 Exceptions.push_back(U);
5065 continue;
5066 }
5067
5068 // Substitute into the pack expansion pattern for each slice of the
5069 // pack.
5070 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5071 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5072
5073 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5074 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5075 return true;
5076
5077 Exceptions.push_back(U);
5078 }
5079 } else {
5080 QualType U = getDerived().TransformType(T);
5081 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5082 return true;
5083 if (T != U)
5084 Changed = true;
5085
5086 Exceptions.push_back(U);
5087 }
5088 }
5089
5090 ESI.Exceptions = Exceptions;
5091 return false;
5092}
5093
5094template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005095QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005096 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005097 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005098 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005099 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005100 if (ResultType.isNull())
5101 return QualType();
5102
5103 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005104 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005105 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5106
5107 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005108 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005109 NewTL.setLParenLoc(TL.getLParenLoc());
5110 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005111 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005112
5113 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005114}
Mike Stump11289f42009-09-09 15:08:12 +00005115
John McCallb96ec562009-12-04 22:46:56 +00005116template<typename Derived> QualType
5117TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005118 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005119 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005120 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005121 if (!D)
5122 return QualType();
5123
5124 QualType Result = TL.getType();
5125 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5126 Result = getDerived().RebuildUnresolvedUsingType(D);
5127 if (Result.isNull())
5128 return QualType();
5129 }
5130
5131 // We might get an arbitrary type spec type back. We should at
5132 // least always get a type spec type, though.
5133 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5134 NewTL.setNameLoc(TL.getNameLoc());
5135
5136 return Result;
5137}
5138
Douglas Gregord6ff3322009-08-04 16:50:30 +00005139template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005140QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005141 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005142 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005143 TypedefNameDecl *Typedef
5144 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5145 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005146 if (!Typedef)
5147 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005148
John McCall550e0c22009-10-21 00:40:46 +00005149 QualType Result = TL.getType();
5150 if (getDerived().AlwaysRebuild() ||
5151 Typedef != T->getDecl()) {
5152 Result = getDerived().RebuildTypedefType(Typedef);
5153 if (Result.isNull())
5154 return QualType();
5155 }
Mike Stump11289f42009-09-09 15:08:12 +00005156
John McCall550e0c22009-10-21 00:40:46 +00005157 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5158 NewTL.setNameLoc(TL.getNameLoc());
5159
5160 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161}
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005164QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005165 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005166 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005167 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5168 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005169
John McCalldadc5752010-08-24 06:29:42 +00005170 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171 if (E.isInvalid())
5172 return QualType();
5173
Eli Friedmane4f22df2012-02-29 04:03:55 +00005174 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5175 if (E.isInvalid())
5176 return QualType();
5177
John McCall550e0c22009-10-21 00:40:46 +00005178 QualType Result = TL.getType();
5179 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005180 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005181 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005182 if (Result.isNull())
5183 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005185 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005186
John McCall550e0c22009-10-21 00:40:46 +00005187 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005188 NewTL.setTypeofLoc(TL.getTypeofLoc());
5189 NewTL.setLParenLoc(TL.getLParenLoc());
5190 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005191
5192 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005193}
Mike Stump11289f42009-09-09 15:08:12 +00005194
5195template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005196QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005197 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005198 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5199 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5200 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005202
John McCall550e0c22009-10-21 00:40:46 +00005203 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005204 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5205 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005206 if (Result.isNull())
5207 return QualType();
5208 }
Mike Stump11289f42009-09-09 15:08:12 +00005209
John McCall550e0c22009-10-21 00:40:46 +00005210 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005211 NewTL.setTypeofLoc(TL.getTypeofLoc());
5212 NewTL.setLParenLoc(TL.getLParenLoc());
5213 NewTL.setRParenLoc(TL.getRParenLoc());
5214 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005215
5216 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
5219template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005220QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005221 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005222 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005223
Douglas Gregore922c772009-08-04 22:27:00 +00005224 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005225 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5226 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005227
John McCalldadc5752010-08-24 06:29:42 +00005228 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229 if (E.isInvalid())
5230 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005231
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005232 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005233 if (E.isInvalid())
5234 return QualType();
5235
John McCall550e0c22009-10-21 00:40:46 +00005236 QualType Result = TL.getType();
5237 if (getDerived().AlwaysRebuild() ||
5238 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005239 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005240 if (Result.isNull())
5241 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005242 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005243 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCall550e0c22009-10-21 00:40:46 +00005245 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5246 NewTL.setNameLoc(TL.getNameLoc());
5247
5248 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249}
5250
5251template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005252QualType TreeTransform<Derived>::TransformUnaryTransformType(
5253 TypeLocBuilder &TLB,
5254 UnaryTransformTypeLoc TL) {
5255 QualType Result = TL.getType();
5256 if (Result->isDependentType()) {
5257 const UnaryTransformType *T = TL.getTypePtr();
5258 QualType NewBase =
5259 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5260 Result = getDerived().RebuildUnaryTransformType(NewBase,
5261 T->getUTTKind(),
5262 TL.getKWLoc());
5263 if (Result.isNull())
5264 return QualType();
5265 }
5266
5267 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5268 NewTL.setKWLoc(TL.getKWLoc());
5269 NewTL.setParensRange(TL.getParensRange());
5270 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5271 return Result;
5272}
5273
5274template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005275QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5276 AutoTypeLoc TL) {
5277 const AutoType *T = TL.getTypePtr();
5278 QualType OldDeduced = T->getDeducedType();
5279 QualType NewDeduced;
5280 if (!OldDeduced.isNull()) {
5281 NewDeduced = getDerived().TransformType(OldDeduced);
5282 if (NewDeduced.isNull())
5283 return QualType();
5284 }
5285
5286 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005287 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5288 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005289 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005290 if (Result.isNull())
5291 return QualType();
5292 }
5293
5294 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5295 NewTL.setNameLoc(TL.getNameLoc());
5296
5297 return Result;
5298}
5299
5300template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005301QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005302 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005303 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005305 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5306 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005307 if (!Record)
5308 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005309
John McCall550e0c22009-10-21 00:40:46 +00005310 QualType Result = TL.getType();
5311 if (getDerived().AlwaysRebuild() ||
5312 Record != T->getDecl()) {
5313 Result = getDerived().RebuildRecordType(Record);
5314 if (Result.isNull())
5315 return QualType();
5316 }
Mike Stump11289f42009-09-09 15:08:12 +00005317
John McCall550e0c22009-10-21 00:40:46 +00005318 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5319 NewTL.setNameLoc(TL.getNameLoc());
5320
5321 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005322}
Mike Stump11289f42009-09-09 15:08:12 +00005323
5324template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005325QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005326 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005327 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005328 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005329 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5330 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005331 if (!Enum)
5332 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005333
John McCall550e0c22009-10-21 00:40:46 +00005334 QualType Result = TL.getType();
5335 if (getDerived().AlwaysRebuild() ||
5336 Enum != T->getDecl()) {
5337 Result = getDerived().RebuildEnumType(Enum);
5338 if (Result.isNull())
5339 return QualType();
5340 }
Mike Stump11289f42009-09-09 15:08:12 +00005341
John McCall550e0c22009-10-21 00:40:46 +00005342 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5343 NewTL.setNameLoc(TL.getNameLoc());
5344
5345 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005346}
John McCallfcc33b02009-09-05 00:15:47 +00005347
John McCalle78aac42010-03-10 03:28:59 +00005348template<typename Derived>
5349QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5350 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005351 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005352 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5353 TL.getTypePtr()->getDecl());
5354 if (!D) return QualType();
5355
5356 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5357 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5358 return T;
5359}
5360
Douglas Gregord6ff3322009-08-04 16:50:30 +00005361template<typename Derived>
5362QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005363 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005364 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005365 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005366}
5367
Mike Stump11289f42009-09-09 15:08:12 +00005368template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005369QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005370 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005371 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005372 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005373
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005374 // Substitute into the replacement type, which itself might involve something
5375 // that needs to be transformed. This only tends to occur with default
5376 // template arguments of template template parameters.
5377 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5378 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5379 if (Replacement.isNull())
5380 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005381
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005382 // Always canonicalize the replacement type.
5383 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5384 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005385 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005386 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005387
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005388 // Propagate type-source information.
5389 SubstTemplateTypeParmTypeLoc NewTL
5390 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5391 NewTL.setNameLoc(TL.getNameLoc());
5392 return Result;
5393
John McCallcebee162009-10-18 09:09:24 +00005394}
5395
5396template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005397QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5398 TypeLocBuilder &TLB,
5399 SubstTemplateTypeParmPackTypeLoc TL) {
5400 return TransformTypeSpecType(TLB, TL);
5401}
5402
5403template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005404QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005405 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005406 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005407 const TemplateSpecializationType *T = TL.getTypePtr();
5408
Douglas Gregordf846d12011-03-02 18:46:51 +00005409 // The nested-name-specifier never matters in a TemplateSpecializationType,
5410 // because we can't have a dependent nested-name-specifier anyway.
5411 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005412 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005413 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5414 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005415 if (Template.isNull())
5416 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005417
John McCall31f82722010-11-12 08:19:04 +00005418 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5419}
5420
Eli Friedman0dfb8892011-10-06 23:00:33 +00005421template<typename Derived>
5422QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5423 AtomicTypeLoc TL) {
5424 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5425 if (ValueType.isNull())
5426 return QualType();
5427
5428 QualType Result = TL.getType();
5429 if (getDerived().AlwaysRebuild() ||
5430 ValueType != TL.getValueLoc().getType()) {
5431 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5432 if (Result.isNull())
5433 return QualType();
5434 }
5435
5436 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5437 NewTL.setKWLoc(TL.getKWLoc());
5438 NewTL.setLParenLoc(TL.getLParenLoc());
5439 NewTL.setRParenLoc(TL.getRParenLoc());
5440
5441 return Result;
5442}
5443
Xiuli Pan9c14e282016-01-09 12:53:17 +00005444template <typename Derived>
5445QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5446 PipeTypeLoc TL) {
5447 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5448 if (ValueType.isNull())
5449 return QualType();
5450
5451 QualType Result = TL.getType();
5452 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5453 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5454 if (Result.isNull())
5455 return QualType();
5456 }
5457
5458 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5459 NewTL.setKWLoc(TL.getKWLoc());
5460
5461 return Result;
5462}
5463
Chad Rosier1dcde962012-08-08 18:46:20 +00005464 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005465 /// container that provides a \c getArgLoc() member function.
5466 ///
5467 /// This iterator is intended to be used with the iterator form of
5468 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5469 template<typename ArgLocContainer>
5470 class TemplateArgumentLocContainerIterator {
5471 ArgLocContainer *Container;
5472 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005473
Douglas Gregorfe921a72010-12-20 23:36:19 +00005474 public:
5475 typedef TemplateArgumentLoc value_type;
5476 typedef TemplateArgumentLoc reference;
5477 typedef int difference_type;
5478 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005479
Douglas Gregorfe921a72010-12-20 23:36:19 +00005480 class pointer {
5481 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005482
Douglas Gregorfe921a72010-12-20 23:36:19 +00005483 public:
5484 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
Douglas Gregorfe921a72010-12-20 23:36:19 +00005486 const TemplateArgumentLoc *operator->() const {
5487 return &Arg;
5488 }
5489 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005490
5491
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005492 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005493
Douglas Gregorfe921a72010-12-20 23:36:19 +00005494 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5495 unsigned Index)
5496 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005497
Douglas Gregorfe921a72010-12-20 23:36:19 +00005498 TemplateArgumentLocContainerIterator &operator++() {
5499 ++Index;
5500 return *this;
5501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005502
Douglas Gregorfe921a72010-12-20 23:36:19 +00005503 TemplateArgumentLocContainerIterator operator++(int) {
5504 TemplateArgumentLocContainerIterator Old(*this);
5505 ++(*this);
5506 return Old;
5507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
Douglas Gregorfe921a72010-12-20 23:36:19 +00005509 TemplateArgumentLoc operator*() const {
5510 return Container->getArgLoc(Index);
5511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005512
Douglas Gregorfe921a72010-12-20 23:36:19 +00005513 pointer operator->() const {
5514 return pointer(Container->getArgLoc(Index));
5515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
Douglas Gregorfe921a72010-12-20 23:36:19 +00005517 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005518 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005519 return X.Container == Y.Container && X.Index == Y.Index;
5520 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
Douglas Gregorfe921a72010-12-20 23:36:19 +00005522 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005523 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005524 return !(X == Y);
5525 }
5526 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005527
5528
John McCall31f82722010-11-12 08:19:04 +00005529template <typename Derived>
5530QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5531 TypeLocBuilder &TLB,
5532 TemplateSpecializationTypeLoc TL,
5533 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005534 TemplateArgumentListInfo NewTemplateArgs;
5535 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5536 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005537 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5538 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005539 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005540 ArgIterator(TL, TL.getNumArgs()),
5541 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005542 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005543
John McCall0ad16662009-10-29 08:12:44 +00005544 // FIXME: maybe don't rebuild if all the template arguments are the same.
5545
5546 QualType Result =
5547 getDerived().RebuildTemplateSpecializationType(Template,
5548 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005549 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005550
5551 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005552 // Specializations of template template parameters are represented as
5553 // TemplateSpecializationTypes, and substitution of type alias templates
5554 // within a dependent context can transform them into
5555 // DependentTemplateSpecializationTypes.
5556 if (isa<DependentTemplateSpecializationType>(Result)) {
5557 DependentTemplateSpecializationTypeLoc NewTL
5558 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005559 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005560 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005561 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005562 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005563 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());
5567 return Result;
5568 }
5569
John McCall0ad16662009-10-29 08:12:44 +00005570 TemplateSpecializationTypeLoc NewTL
5571 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005572 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005573 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5574 NewTL.setLAngleLoc(TL.getLAngleLoc());
5575 NewTL.setRAngleLoc(TL.getRAngleLoc());
5576 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5577 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005578 }
Mike Stump11289f42009-09-09 15:08:12 +00005579
John McCall0ad16662009-10-29 08:12:44 +00005580 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005581}
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregor5a064722011-02-28 17:23:35 +00005583template <typename Derived>
5584QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5585 TypeLocBuilder &TLB,
5586 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005587 TemplateName Template,
5588 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005589 TemplateArgumentListInfo NewTemplateArgs;
5590 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5591 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5592 typedef TemplateArgumentLocContainerIterator<
5593 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005594 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005595 ArgIterator(TL, TL.getNumArgs()),
5596 NewTemplateArgs))
5597 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005598
Douglas Gregor5a064722011-02-28 17:23:35 +00005599 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005600
Douglas Gregor5a064722011-02-28 17:23:35 +00005601 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5602 QualType Result
5603 = getSema().Context.getDependentTemplateSpecializationType(
5604 TL.getTypePtr()->getKeyword(),
5605 DTN->getQualifier(),
5606 DTN->getIdentifier(),
5607 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005608
Douglas Gregor5a064722011-02-28 17:23:35 +00005609 DependentTemplateSpecializationTypeLoc NewTL
5610 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005611 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005612 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005613 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005614 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005615 NewTL.setLAngleLoc(TL.getLAngleLoc());
5616 NewTL.setRAngleLoc(TL.getRAngleLoc());
5617 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5618 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5619 return Result;
5620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005621
5622 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005623 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005624 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005625 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005626
Douglas Gregor5a064722011-02-28 17:23:35 +00005627 if (!Result.isNull()) {
5628 /// FIXME: Wrap this in an elaborated-type-specifier?
5629 TemplateSpecializationTypeLoc NewTL
5630 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005631 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005632 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005633 NewTL.setLAngleLoc(TL.getLAngleLoc());
5634 NewTL.setRAngleLoc(TL.getRAngleLoc());
5635 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5636 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005638
Douglas Gregor5a064722011-02-28 17:23:35 +00005639 return Result;
5640}
5641
Mike Stump11289f42009-09-09 15:08:12 +00005642template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005643QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005644TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005645 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005646 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005647
Douglas Gregor844cb502011-03-01 18:12:44 +00005648 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005649 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005650 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005651 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005652 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5653 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005654 return QualType();
5655 }
Mike Stump11289f42009-09-09 15:08:12 +00005656
John McCall31f82722010-11-12 08:19:04 +00005657 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5658 if (NamedT.isNull())
5659 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005660
Richard Smith3f1b5d02011-05-05 21:57:07 +00005661 // C++0x [dcl.type.elab]p2:
5662 // If the identifier resolves to a typedef-name or the simple-template-id
5663 // resolves to an alias template specialization, the
5664 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005665 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5666 if (const TemplateSpecializationType *TST =
5667 NamedT->getAs<TemplateSpecializationType>()) {
5668 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005669 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5670 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005671 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5672 diag::err_tag_reference_non_tag) << 4;
5673 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5674 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005675 }
5676 }
5677
John McCall550e0c22009-10-21 00:40:46 +00005678 QualType Result = TL.getType();
5679 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005680 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005681 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005682 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005683 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005684 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005685 if (Result.isNull())
5686 return QualType();
5687 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005688
Abramo Bagnara6150c882010-05-11 21:36:43 +00005689 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005690 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005691 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005692 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005693}
Mike Stump11289f42009-09-09 15:08:12 +00005694
5695template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005696QualType TreeTransform<Derived>::TransformAttributedType(
5697 TypeLocBuilder &TLB,
5698 AttributedTypeLoc TL) {
5699 const AttributedType *oldType = TL.getTypePtr();
5700 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5701 if (modifiedType.isNull())
5702 return QualType();
5703
5704 QualType result = TL.getType();
5705
5706 // FIXME: dependent operand expressions?
5707 if (getDerived().AlwaysRebuild() ||
5708 modifiedType != oldType->getModifiedType()) {
5709 // TODO: this is really lame; we should really be rebuilding the
5710 // equivalent type from first principles.
5711 QualType equivalentType
5712 = getDerived().TransformType(oldType->getEquivalentType());
5713 if (equivalentType.isNull())
5714 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005715
5716 // Check whether we can add nullability; it is only represented as
5717 // type sugar, and therefore cannot be diagnosed in any other way.
5718 if (auto nullability = oldType->getImmediateNullability()) {
5719 if (!modifiedType->canHaveNullability()) {
5720 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005721 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005722 return QualType();
5723 }
5724 }
5725
John McCall81904512011-01-06 01:58:22 +00005726 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5727 modifiedType,
5728 equivalentType);
5729 }
5730
5731 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5732 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5733 if (TL.hasAttrOperand())
5734 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5735 if (TL.hasAttrExprOperand())
5736 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5737 else if (TL.hasAttrEnumOperand())
5738 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5739
5740 return result;
5741}
5742
5743template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005744QualType
5745TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5746 ParenTypeLoc TL) {
5747 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5748 if (Inner.isNull())
5749 return QualType();
5750
5751 QualType Result = TL.getType();
5752 if (getDerived().AlwaysRebuild() ||
5753 Inner != TL.getInnerLoc().getType()) {
5754 Result = getDerived().RebuildParenType(Inner);
5755 if (Result.isNull())
5756 return QualType();
5757 }
5758
5759 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5760 NewTL.setLParenLoc(TL.getLParenLoc());
5761 NewTL.setRParenLoc(TL.getRParenLoc());
5762 return Result;
5763}
5764
5765template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005766QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005767 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005768 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005769
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005770 NestedNameSpecifierLoc QualifierLoc
5771 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5772 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005773 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005774
John McCallc392f372010-06-11 00:33:02 +00005775 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005776 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005777 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005778 QualifierLoc,
5779 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005780 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005781 if (Result.isNull())
5782 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005783
Abramo Bagnarad7548482010-05-19 21:37:53 +00005784 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5785 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005786 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5787
Abramo Bagnarad7548482010-05-19 21:37:53 +00005788 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005789 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005790 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005791 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005792 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005793 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005794 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005795 NewTL.setNameLoc(TL.getNameLoc());
5796 }
John McCall550e0c22009-10-21 00:40:46 +00005797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregord6ff3322009-08-04 16:50:30 +00005800template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005801QualType TreeTransform<Derived>::
5802 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005803 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005804 NestedNameSpecifierLoc QualifierLoc;
5805 if (TL.getQualifierLoc()) {
5806 QualifierLoc
5807 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5808 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005809 return QualType();
5810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
John McCall31f82722010-11-12 08:19:04 +00005812 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005813 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005814}
5815
5816template<typename Derived>
5817QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005818TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5819 DependentTemplateSpecializationTypeLoc TL,
5820 NestedNameSpecifierLoc QualifierLoc) {
5821 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Douglas Gregora7a795b2011-03-01 20:11:18 +00005823 TemplateArgumentListInfo NewTemplateArgs;
5824 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5825 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
Douglas Gregora7a795b2011-03-01 20:11:18 +00005827 typedef TemplateArgumentLocContainerIterator<
5828 DependentTemplateSpecializationTypeLoc> ArgIterator;
5829 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5830 ArgIterator(TL, TL.getNumArgs()),
5831 NewTemplateArgs))
5832 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005833
Douglas Gregora7a795b2011-03-01 20:11:18 +00005834 QualType Result
5835 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5836 QualifierLoc,
5837 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005838 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005839 NewTemplateArgs);
5840 if (Result.isNull())
5841 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005842
Douglas Gregora7a795b2011-03-01 20:11:18 +00005843 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5844 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
Douglas Gregora7a795b2011-03-01 20:11:18 +00005846 // Copy information relevant to the template specialization.
5847 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005848 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005849 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005850 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005851 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5852 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005853 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005854 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005855
Douglas Gregora7a795b2011-03-01 20:11:18 +00005856 // Copy information relevant to the elaborated type.
5857 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005858 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005859 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005860 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5861 DependentTemplateSpecializationTypeLoc SpecTL
5862 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005863 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005864 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005865 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005866 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005867 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5868 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005869 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005870 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005871 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005872 TemplateSpecializationTypeLoc SpecTL
5873 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005874 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005875 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005876 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5877 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005878 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005879 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005880 }
5881 return Result;
5882}
5883
5884template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005885QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5886 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005887 QualType Pattern
5888 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005889 if (Pattern.isNull())
5890 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
5892 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005893 if (getDerived().AlwaysRebuild() ||
5894 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005895 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005896 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005897 TL.getEllipsisLoc(),
5898 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005899 if (Result.isNull())
5900 return QualType();
5901 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005902
Douglas Gregor822d0302011-01-12 17:07:58 +00005903 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5904 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5905 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005906}
5907
5908template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005909QualType
5910TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005911 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005912 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005913 TLB.pushFullCopy(TL);
5914 return TL.getType();
5915}
5916
5917template<typename Derived>
5918QualType
5919TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005920 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005921 // Transform base type.
5922 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5923 if (BaseType.isNull())
5924 return QualType();
5925
5926 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5927
5928 // Transform type arguments.
5929 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5930 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5931 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5932 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5933 QualType TypeArg = TypeArgInfo->getType();
5934 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5935 AnyChanged = true;
5936
5937 // We have a pack expansion. Instantiate it.
5938 const auto *PackExpansion = PackExpansionLoc.getType()
5939 ->castAs<PackExpansionType>();
5940 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5941 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5942 Unexpanded);
5943 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5944
5945 // Determine whether the set of unexpanded parameter packs can
5946 // and should be expanded.
5947 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5948 bool Expand = false;
5949 bool RetainExpansion = false;
5950 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5951 if (getDerived().TryExpandParameterPacks(
5952 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5953 Unexpanded, Expand, RetainExpansion, NumExpansions))
5954 return QualType();
5955
5956 if (!Expand) {
5957 // We can't expand this pack expansion into separate arguments yet;
5958 // just substitute into the pattern and create a new pack expansion
5959 // type.
5960 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5961
5962 TypeLocBuilder TypeArgBuilder;
5963 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5964 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5965 PatternLoc);
5966 if (NewPatternType.isNull())
5967 return QualType();
5968
5969 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5970 NewPatternType, NumExpansions);
5971 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5972 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5973 NewTypeArgInfos.push_back(
5974 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5975 continue;
5976 }
5977
5978 // Substitute into the pack expansion pattern for each slice of the
5979 // pack.
5980 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5981 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5982
5983 TypeLocBuilder TypeArgBuilder;
5984 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5985
5986 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5987 PatternLoc);
5988 if (NewTypeArg.isNull())
5989 return QualType();
5990
5991 NewTypeArgInfos.push_back(
5992 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5993 }
5994
5995 continue;
5996 }
5997
5998 TypeLocBuilder TypeArgBuilder;
5999 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6000 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6001 if (NewTypeArg.isNull())
6002 return QualType();
6003
6004 // If nothing changed, just keep the old TypeSourceInfo.
6005 if (NewTypeArg == TypeArg) {
6006 NewTypeArgInfos.push_back(TypeArgInfo);
6007 continue;
6008 }
6009
6010 NewTypeArgInfos.push_back(
6011 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6012 AnyChanged = true;
6013 }
6014
6015 QualType Result = TL.getType();
6016 if (getDerived().AlwaysRebuild() || AnyChanged) {
6017 // Rebuild the type.
6018 Result = getDerived().RebuildObjCObjectType(
6019 BaseType,
6020 TL.getLocStart(),
6021 TL.getTypeArgsLAngleLoc(),
6022 NewTypeArgInfos,
6023 TL.getTypeArgsRAngleLoc(),
6024 TL.getProtocolLAngleLoc(),
6025 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6026 TL.getNumProtocols()),
6027 TL.getProtocolLocs(),
6028 TL.getProtocolRAngleLoc());
6029
6030 if (Result.isNull())
6031 return QualType();
6032 }
6033
6034 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006035 NewT.setHasBaseTypeAsWritten(true);
6036 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6037 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6038 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6039 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6040 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6041 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6042 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6043 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6044 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006045}
Mike Stump11289f42009-09-09 15:08:12 +00006046
6047template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006048QualType
6049TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006050 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006051 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6052 if (PointeeType.isNull())
6053 return QualType();
6054
6055 QualType Result = TL.getType();
6056 if (getDerived().AlwaysRebuild() ||
6057 PointeeType != TL.getPointeeLoc().getType()) {
6058 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6059 TL.getStarLoc());
6060 if (Result.isNull())
6061 return QualType();
6062 }
6063
6064 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6065 NewT.setStarLoc(TL.getStarLoc());
6066 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006067}
6068
Douglas Gregord6ff3322009-08-04 16:50:30 +00006069//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006070// Statement transformation
6071//===----------------------------------------------------------------------===//
6072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006073StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006074TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006075 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006076}
6077
6078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006080TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6081 return getDerived().TransformCompoundStmt(S, false);
6082}
6083
6084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006086TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006087 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006088 Sema::CompoundScopeRAII CompoundScope(getSema());
6089
John McCall1ababa62010-08-27 19:56:05 +00006090 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006091 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006092 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006093 for (auto *B : S->body()) {
6094 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006095 if (Result.isInvalid()) {
6096 // Immediately fail if this was a DeclStmt, since it's very
6097 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006098 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006099 return StmtError();
6100
6101 // Otherwise, just keep processing substatements and fail later.
6102 SubStmtInvalid = true;
6103 continue;
6104 }
Mike Stump11289f42009-09-09 15:08:12 +00006105
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006106 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006107 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006108 }
Mike Stump11289f42009-09-09 15:08:12 +00006109
John McCall1ababa62010-08-27 19:56:05 +00006110 if (SubStmtInvalid)
6111 return StmtError();
6112
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 if (!getDerived().AlwaysRebuild() &&
6114 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006115 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006116
6117 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006118 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 S->getRBracLoc(),
6120 IsStmtExpr);
6121}
Mike Stump11289f42009-09-09 15:08:12 +00006122
Douglas Gregorebe10102009-08-20 07:17:43 +00006123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006124StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006125TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006126 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006127 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006128 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6129 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006130
Eli Friedman06577382009-11-19 03:14:00 +00006131 // Transform the left-hand case value.
6132 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006133 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006134 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006136
Eli Friedman06577382009-11-19 03:14:00 +00006137 // Transform the right-hand case value (for the GNU case-range extension).
6138 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006139 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006140 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006141 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006142 }
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 // Build the case statement.
6145 // Case statements are always rebuilt so that they will attached to their
6146 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006147 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006148 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006150 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006151 S->getColonLoc());
6152 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006156 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006158 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006159
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006161 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006162}
6163
6164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006165StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006166TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006167 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006168 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006169 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 // Default statements are always rebuilt
6173 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006174 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006175}
Mike Stump11289f42009-09-09 15:08:12 +00006176
Douglas Gregorebe10102009-08-20 07:17:43 +00006177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006178StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006179TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006180 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006182 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006183
Chris Lattnercab02a62011-02-17 20:34:02 +00006184 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6185 S->getDecl());
6186 if (!LD)
6187 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006188
6189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006191 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006192 cast<LabelDecl>(LD), SourceLocation(),
6193 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006194}
Mike Stump11289f42009-09-09 15:08:12 +00006195
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006196template <typename Derived>
6197const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6198 if (!R)
6199 return R;
6200
6201 switch (R->getKind()) {
6202// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6203#define ATTR(X)
6204#define PRAGMA_SPELLING_ATTR(X) \
6205 case attr::X: \
6206 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6207#include "clang/Basic/AttrList.inc"
6208 default:
6209 return R;
6210 }
6211}
6212
6213template <typename Derived>
6214StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6215 bool AttrsChanged = false;
6216 SmallVector<const Attr *, 1> Attrs;
6217
6218 // Visit attributes and keep track if any are transformed.
6219 for (const auto *I : S->getAttrs()) {
6220 const Attr *R = getDerived().TransformAttr(I);
6221 AttrsChanged |= (I != R);
6222 Attrs.push_back(R);
6223 }
6224
Richard Smithc202b282012-04-14 00:33:13 +00006225 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6226 if (SubStmt.isInvalid())
6227 return StmtError();
6228
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006229 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006230 return S;
6231
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006232 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006233 SubStmt.get());
6234}
6235
6236template<typename Derived>
6237StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006238TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006239 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006240 Sema::ConditionResult Cond = getDerived().TransformCondition(
6241 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006242 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6243 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006244 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006246
Richard Smithb130fe72016-06-23 19:16:49 +00006247 // If this is a constexpr if, determine which arm we should instantiate.
6248 llvm::Optional<bool> ConstexprConditionValue;
6249 if (S->isConstexpr())
6250 ConstexprConditionValue = Cond.getKnownValue();
6251
Douglas Gregorebe10102009-08-20 07:17:43 +00006252 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006253 StmtResult Then;
6254 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6255 Then = getDerived().TransformStmt(S->getThen());
6256 if (Then.isInvalid())
6257 return StmtError();
6258 } else {
6259 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6260 }
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregorebe10102009-08-20 07:17:43 +00006262 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006263 StmtResult Else;
6264 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6265 Else = getDerived().TransformStmt(S->getElse());
6266 if (Else.isInvalid())
6267 return StmtError();
6268 }
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006271 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006272 Then.get() == S->getThen() &&
6273 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006274 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006275
Richard Smithb130fe72016-06-23 19:16:49 +00006276 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6277 Then.get(), S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006278}
6279
6280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006281StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006282TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006283 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006284 Sema::ConditionResult Cond = getDerived().TransformCondition(
6285 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6286 Sema::ConditionKind::Switch);
6287 if (Cond.isInvalid())
6288 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregorebe10102009-08-20 07:17:43 +00006290 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006291 StmtResult Switch
Richard Smith03a4aa32016-06-23 19:02:52 +00006292 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006293 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006294 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregorebe10102009-08-20 07:17:43 +00006296 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006297 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregorebe10102009-08-20 07:17:43 +00006301 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006302 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6303 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006304}
Mike Stump11289f42009-09-09 15:08:12 +00006305
Douglas Gregorebe10102009-08-20 07:17:43 +00006306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006307StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006308TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006309 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006310 Sema::ConditionResult Cond = getDerived().TransformCondition(
6311 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6312 Sema::ConditionKind::Boolean);
6313 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006314 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006315
Douglas Gregorebe10102009-08-20 07:17:43 +00006316 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006317 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006318 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006320
Douglas Gregorebe10102009-08-20 07:17:43 +00006321 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006322 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006323 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006324 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006325
Richard Smith03a4aa32016-06-23 19:02:52 +00006326 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006327}
Mike Stump11289f42009-09-09 15:08:12 +00006328
Douglas Gregorebe10102009-08-20 07:17:43 +00006329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006330StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006331TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006333 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006334 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006335 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006336
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006337 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006339 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006341
Douglas Gregorebe10102009-08-20 07:17:43 +00006342 if (!getDerived().AlwaysRebuild() &&
6343 Cond.get() == S->getCond() &&
6344 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006345 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006346
John McCallb268a282010-08-23 23:25:46 +00006347 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6348 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006349 S->getRParenLoc());
6350}
Mike Stump11289f42009-09-09 15:08:12 +00006351
Douglas Gregorebe10102009-08-20 07:17:43 +00006352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006353StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006354TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006355 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006356 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006357 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006358 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006359
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006360 // In OpenMP loop region loop control variable must be captured and be
6361 // private. Perform analysis of first part (if any).
6362 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6363 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6364
Douglas Gregorebe10102009-08-20 07:17:43 +00006365 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006366 Sema::ConditionResult Cond = getDerived().TransformCondition(
6367 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6368 Sema::ConditionKind::Boolean);
6369 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006373 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006374 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006376
Richard Smith945f8d32013-01-14 22:39:08 +00006377 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006378 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006382 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006383 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006385
Douglas Gregorebe10102009-08-20 07:17:43 +00006386 if (!getDerived().AlwaysRebuild() &&
6387 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006388 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006389 Inc.get() == S->getInc() &&
6390 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006391 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregorebe10102009-08-20 07:17:43 +00006393 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006394 Init.get(), Cond, FullInc,
6395 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006396}
6397
6398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006399StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006400TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006401 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6402 S->getLabel());
6403 if (!LD)
6404 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006405
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006407 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006408 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006409}
6410
6411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006412StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006413TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006414 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006416 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006417 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006418
Douglas Gregorebe10102009-08-20 07:17:43 +00006419 if (!getDerived().AlwaysRebuild() &&
6420 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006421 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006422
6423 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006424 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006425}
6426
6427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006429TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006430 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006431}
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregorebe10102009-08-20 07:17:43 +00006433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006434StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006435TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006436 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006437}
Mike Stump11289f42009-09-09 15:08:12 +00006438
Douglas Gregorebe10102009-08-20 07:17:43 +00006439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006441TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006442 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6443 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006446
Mike Stump11289f42009-09-09 15:08:12 +00006447 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006448 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006449 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006450}
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregorebe10102009-08-20 07:17:43 +00006452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006453StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006454TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006455 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006456 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006457 for (auto *D : S->decls()) {
6458 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006459 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006460 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006461
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006462 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006463 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006464
Douglas Gregorebe10102009-08-20 07:17:43 +00006465 Decls.push_back(Transformed);
6466 }
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregorebe10102009-08-20 07:17:43 +00006468 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006469 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006470
Rafael Espindolaab417692013-07-09 12:05:01 +00006471 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006472}
Mike Stump11289f42009-09-09 15:08:12 +00006473
Douglas Gregorebe10102009-08-20 07:17:43 +00006474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006475StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006476TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006477
Benjamin Kramerf0623432012-08-23 22:51:59 +00006478 SmallVector<Expr*, 8> Constraints;
6479 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006480 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006481
John McCalldadc5752010-08-24 06:29:42 +00006482 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006483 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006484
6485 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006486
Anders Carlssonaaeef072010-01-24 05:50:09 +00006487 // Go through the outputs.
6488 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006489 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006490
Anders Carlssonaaeef072010-01-24 05:50:09 +00006491 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006492 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006493
Anders Carlssonaaeef072010-01-24 05:50:09 +00006494 // Transform the output expr.
6495 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006496 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006497 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006499
Anders Carlssonaaeef072010-01-24 05:50:09 +00006500 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006501
John McCallb268a282010-08-23 23:25:46 +00006502 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006504
Anders Carlssonaaeef072010-01-24 05:50:09 +00006505 // Go through the inputs.
6506 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006507 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006508
Anders Carlssonaaeef072010-01-24 05:50:09 +00006509 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006510 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006511
Anders Carlssonaaeef072010-01-24 05:50:09 +00006512 // Transform the input expr.
6513 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006514 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006515 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006516 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006517
Anders Carlssonaaeef072010-01-24 05:50:09 +00006518 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006519
John McCallb268a282010-08-23 23:25:46 +00006520 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006522
Anders Carlssonaaeef072010-01-24 05:50:09 +00006523 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006524 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006525
6526 // Go through the clobbers.
6527 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006528 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006529
6530 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006531 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006532 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6533 S->isVolatile(), S->getNumOutputs(),
6534 S->getNumInputs(), Names.data(),
6535 Constraints, Exprs, AsmString.get(),
6536 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006537}
6538
Chad Rosier32503022012-06-11 20:47:18 +00006539template<typename Derived>
6540StmtResult
6541TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006542 ArrayRef<Token> AsmToks =
6543 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006544
John McCallf413f5e2013-05-03 00:10:13 +00006545 bool HadError = false, HadChange = false;
6546
6547 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6548 SmallVector<Expr*, 8> TransformedExprs;
6549 TransformedExprs.reserve(SrcExprs.size());
6550 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6551 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6552 if (!Result.isUsable()) {
6553 HadError = true;
6554 } else {
6555 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006556 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006557 }
6558 }
6559
6560 if (HadError) return StmtError();
6561 if (!HadChange && !getDerived().AlwaysRebuild())
6562 return Owned(S);
6563
Chad Rosierb6f46c12012-08-15 16:53:30 +00006564 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006565 AsmToks, S->getAsmString(),
6566 S->getNumOutputs(), S->getNumInputs(),
6567 S->getAllConstraints(), S->getClobbers(),
6568 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006569}
Douglas Gregorebe10102009-08-20 07:17:43 +00006570
Richard Smith9f690bd2015-10-27 06:02:45 +00006571// C++ Coroutines TS
6572
6573template<typename Derived>
6574StmtResult
6575TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6576 // The coroutine body should be re-formed by the caller if necessary.
6577 return getDerived().TransformStmt(S->getBody());
6578}
6579
6580template<typename Derived>
6581StmtResult
6582TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6583 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6584 /*NotCopyInit*/false);
6585 if (Result.isInvalid())
6586 return StmtError();
6587
6588 // Always rebuild; we don't know if this needs to be injected into a new
6589 // context or if the promise type has changed.
6590 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6591}
6592
6593template<typename Derived>
6594ExprResult
6595TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6596 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6597 /*NotCopyInit*/false);
6598 if (Result.isInvalid())
6599 return ExprError();
6600
6601 // Always rebuild; we don't know if this needs to be injected into a new
6602 // context or if the promise type has changed.
6603 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6604}
6605
6606template<typename Derived>
6607ExprResult
6608TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6609 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6610 /*NotCopyInit*/false);
6611 if (Result.isInvalid())
6612 return ExprError();
6613
6614 // Always rebuild; we don't know if this needs to be injected into a new
6615 // context or if the promise type has changed.
6616 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6617}
6618
6619// Objective-C Statements.
6620
Douglas Gregorebe10102009-08-20 07:17:43 +00006621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006622StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006623TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006624 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006625 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006626 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006627 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006628
Douglas Gregor96c79492010-04-23 22:50:49 +00006629 // Transform the @catch statements (if present).
6630 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006631 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006632 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006633 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006634 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006635 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006636 if (Catch.get() != S->getCatchStmt(I))
6637 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006638 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006640
Douglas Gregor306de2f2010-04-22 23:59:56 +00006641 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006642 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006643 if (S->getFinallyStmt()) {
6644 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6645 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006647 }
6648
6649 // If nothing changed, just retain this statement.
6650 if (!getDerived().AlwaysRebuild() &&
6651 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006652 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006653 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006654 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006655
Douglas Gregor306de2f2010-04-22 23:59:56 +00006656 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006657 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006658 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006659}
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregorebe10102009-08-20 07:17:43 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006663TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006664 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006665 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006666 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006667 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006668 if (FromVar->getTypeSourceInfo()) {
6669 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6670 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006673
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006674 QualType T;
6675 if (TSInfo)
6676 T = TSInfo->getType();
6677 else {
6678 T = getDerived().TransformType(FromVar->getType());
6679 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006680 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006682
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006683 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6684 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006686 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006687
John McCalldadc5752010-08-24 06:29:42 +00006688 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006689 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006690 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006691
6692 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006693 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006694 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006695}
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregorebe10102009-08-20 07:17:43 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006699TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006700 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006701 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006702 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006704
Douglas Gregor306de2f2010-04-22 23:59:56 +00006705 // If nothing changed, just retain this statement.
6706 if (!getDerived().AlwaysRebuild() &&
6707 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006708 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006709
6710 // Build a new statement.
6711 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006712 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006713}
Mike Stump11289f42009-09-09 15:08:12 +00006714
Douglas Gregorebe10102009-08-20 07:17:43 +00006715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006717TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006718 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006719 if (S->getThrowExpr()) {
6720 Operand = getDerived().TransformExpr(S->getThrowExpr());
6721 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006722 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006724
Douglas Gregor2900c162010-04-22 21:44:01 +00006725 if (!getDerived().AlwaysRebuild() &&
6726 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006727 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006728
John McCallb268a282010-08-23 23:25:46 +00006729 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006730}
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregorebe10102009-08-20 07:17:43 +00006732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006733StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006734TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006735 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006736 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006737 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006738 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006740 Object =
6741 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6742 Object.get());
6743 if (Object.isInvalid())
6744 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006745
Douglas Gregor6148de72010-04-22 22:01:21 +00006746 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006747 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006748 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006749 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
Douglas Gregor6148de72010-04-22 22:01:21 +00006751 // If nothing change, just retain the current statement.
6752 if (!getDerived().AlwaysRebuild() &&
6753 Object.get() == S->getSynchExpr() &&
6754 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006755 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006756
6757 // Build a new statement.
6758 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006759 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006760}
6761
6762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006763StmtResult
John McCall31168b02011-06-15 23:02:42 +00006764TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6765 ObjCAutoreleasePoolStmt *S) {
6766 // Transform the body.
6767 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6768 if (Body.isInvalid())
6769 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006770
John McCall31168b02011-06-15 23:02:42 +00006771 // If nothing changed, just retain this statement.
6772 if (!getDerived().AlwaysRebuild() &&
6773 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006774 return S;
John McCall31168b02011-06-15 23:02:42 +00006775
6776 // Build a new statement.
6777 return getDerived().RebuildObjCAutoreleasePoolStmt(
6778 S->getAtLoc(), Body.get());
6779}
6780
6781template<typename Derived>
6782StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006783TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006784 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006785 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006786 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006787 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006788 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006789
Douglas Gregorf68a5082010-04-22 23:10:45 +00006790 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006791 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006792 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006794
Douglas Gregorf68a5082010-04-22 23:10:45 +00006795 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006796 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006797 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006798 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006799
Douglas Gregorf68a5082010-04-22 23:10:45 +00006800 // If nothing changed, just retain this statement.
6801 if (!getDerived().AlwaysRebuild() &&
6802 Element.get() == S->getElement() &&
6803 Collection.get() == S->getCollection() &&
6804 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006805 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006806
Douglas Gregorf68a5082010-04-22 23:10:45 +00006807 // Build a new statement.
6808 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006809 Element.get(),
6810 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006811 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006812 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006813}
6814
David Majnemer5f7efef2013-10-15 09:50:08 +00006815template <typename Derived>
6816StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006817 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006818 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006819 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6820 TypeSourceInfo *T =
6821 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006822 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006824
David Majnemer5f7efef2013-10-15 09:50:08 +00006825 Var = getDerived().RebuildExceptionDecl(
6826 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6827 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006828 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006830 }
Mike Stump11289f42009-09-09 15:08:12 +00006831
Douglas Gregorebe10102009-08-20 07:17:43 +00006832 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006833 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006834 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006835 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006836
David Majnemer5f7efef2013-10-15 09:50:08 +00006837 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006838 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006839 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006840
David Majnemer5f7efef2013-10-15 09:50:08 +00006841 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006842}
Mike Stump11289f42009-09-09 15:08:12 +00006843
David Majnemer5f7efef2013-10-15 09:50:08 +00006844template <typename Derived>
6845StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006846 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006847 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006848 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006849 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006850
Douglas Gregorebe10102009-08-20 07:17:43 +00006851 // Transform the handlers.
6852 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006853 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006855 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006856 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006857 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregorebe10102009-08-20 07:17:43 +00006859 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006860 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006861 }
Mike Stump11289f42009-09-09 15:08:12 +00006862
David Majnemer5f7efef2013-10-15 09:50:08 +00006863 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006864 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006865 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006866
John McCallb268a282010-08-23 23:25:46 +00006867 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006868 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006869}
Mike Stump11289f42009-09-09 15:08:12 +00006870
Richard Smith02e85f32011-04-14 22:09:26 +00006871template<typename Derived>
6872StmtResult
6873TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6874 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6875 if (Range.isInvalid())
6876 return StmtError();
6877
Richard Smith01694c32016-03-20 10:33:40 +00006878 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6879 if (Begin.isInvalid())
6880 return StmtError();
6881 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6882 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006883 return StmtError();
6884
6885 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6886 if (Cond.isInvalid())
6887 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006888 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006889 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006890 if (Cond.isInvalid())
6891 return StmtError();
6892 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006893 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006894
6895 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6896 if (Inc.isInvalid())
6897 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006898 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006899 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006900
6901 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6902 if (LoopVar.isInvalid())
6903 return StmtError();
6904
6905 StmtResult NewStmt = S;
6906 if (getDerived().AlwaysRebuild() ||
6907 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006908 Begin.get() != S->getBeginStmt() ||
6909 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006910 Cond.get() != S->getCond() ||
6911 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006912 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006913 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006914 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006915 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006916 Begin.get(), End.get(),
6917 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006918 Inc.get(), LoopVar.get(),
6919 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006920 if (NewStmt.isInvalid())
6921 return StmtError();
6922 }
Richard Smith02e85f32011-04-14 22:09:26 +00006923
6924 StmtResult Body = getDerived().TransformStmt(S->getBody());
6925 if (Body.isInvalid())
6926 return StmtError();
6927
6928 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6929 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006930 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006931 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006932 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006933 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006934 Begin.get(), End.get(),
6935 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006936 Inc.get(), LoopVar.get(),
6937 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006938 if (NewStmt.isInvalid())
6939 return StmtError();
6940 }
Richard Smith02e85f32011-04-14 22:09:26 +00006941
6942 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006943 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006944
6945 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6946}
6947
John Wiegley1c0675e2011-04-28 01:08:34 +00006948template<typename Derived>
6949StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006950TreeTransform<Derived>::TransformMSDependentExistsStmt(
6951 MSDependentExistsStmt *S) {
6952 // Transform the nested-name-specifier, if any.
6953 NestedNameSpecifierLoc QualifierLoc;
6954 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006955 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006956 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6957 if (!QualifierLoc)
6958 return StmtError();
6959 }
6960
6961 // Transform the declaration name.
6962 DeclarationNameInfo NameInfo = S->getNameInfo();
6963 if (NameInfo.getName()) {
6964 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6965 if (!NameInfo.getName())
6966 return StmtError();
6967 }
6968
6969 // Check whether anything changed.
6970 if (!getDerived().AlwaysRebuild() &&
6971 QualifierLoc == S->getQualifierLoc() &&
6972 NameInfo.getName() == S->getNameInfo().getName())
6973 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006974
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006975 // Determine whether this name exists, if we can.
6976 CXXScopeSpec SS;
6977 SS.Adopt(QualifierLoc);
6978 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006979 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006980 case Sema::IER_Exists:
6981 if (S->isIfExists())
6982 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006983
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006984 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6985
6986 case Sema::IER_DoesNotExist:
6987 if (S->isIfNotExists())
6988 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006989
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006990 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006991
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006992 case Sema::IER_Dependent:
6993 Dependent = true;
6994 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006995
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006996 case Sema::IER_Error:
6997 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006999
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007000 // We need to continue with the instantiation, so do so now.
7001 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7002 if (SubStmt.isInvalid())
7003 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007004
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007005 // If we have resolved the name, just transform to the substatement.
7006 if (!Dependent)
7007 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007008
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007009 // The name is still dependent, so build a dependent expression again.
7010 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7011 S->isIfExists(),
7012 QualifierLoc,
7013 NameInfo,
7014 SubStmt.get());
7015}
7016
7017template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007018ExprResult
7019TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7020 NestedNameSpecifierLoc QualifierLoc;
7021 if (E->getQualifierLoc()) {
7022 QualifierLoc
7023 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7024 if (!QualifierLoc)
7025 return ExprError();
7026 }
7027
7028 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7029 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7030 if (!PD)
7031 return ExprError();
7032
7033 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7034 if (Base.isInvalid())
7035 return ExprError();
7036
7037 return new (SemaRef.getASTContext())
7038 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7039 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7040 QualifierLoc, E->getMemberLoc());
7041}
7042
David Majnemerfad8f482013-10-15 09:33:02 +00007043template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007044ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7045 MSPropertySubscriptExpr *E) {
7046 auto BaseRes = getDerived().TransformExpr(E->getBase());
7047 if (BaseRes.isInvalid())
7048 return ExprError();
7049 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7050 if (IdxRes.isInvalid())
7051 return ExprError();
7052
7053 if (!getDerived().AlwaysRebuild() &&
7054 BaseRes.get() == E->getBase() &&
7055 IdxRes.get() == E->getIdx())
7056 return E;
7057
7058 return getDerived().RebuildArraySubscriptExpr(
7059 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7060}
7061
7062template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007063StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007064 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007065 if (TryBlock.isInvalid())
7066 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007067
7068 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007069 if (Handler.isInvalid())
7070 return StmtError();
7071
David Majnemerfad8f482013-10-15 09:33:02 +00007072 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7073 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007074 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007075
Warren Huntf6be4cb2014-07-25 20:52:51 +00007076 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7077 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007078}
7079
David Majnemerfad8f482013-10-15 09:33:02 +00007080template <typename Derived>
7081StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007082 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007083 if (Block.isInvalid())
7084 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007085
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007086 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007087}
7088
David Majnemerfad8f482013-10-15 09:33:02 +00007089template <typename Derived>
7090StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007091 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007092 if (FilterExpr.isInvalid())
7093 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007094
David Majnemer7e755502013-10-15 09:30:14 +00007095 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007096 if (Block.isInvalid())
7097 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007098
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007099 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7100 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007101}
7102
David Majnemerfad8f482013-10-15 09:33:02 +00007103template <typename Derived>
7104StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7105 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007106 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7107 else
7108 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7109}
7110
Nico Weber9b982072014-07-07 00:12:30 +00007111template<typename Derived>
7112StmtResult
7113TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7114 return S;
7115}
7116
Alexander Musman64d33f12014-06-04 07:53:32 +00007117//===----------------------------------------------------------------------===//
7118// OpenMP directive transformation
7119//===----------------------------------------------------------------------===//
7120template <typename Derived>
7121StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7122 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007123
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007124 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007125 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007126 ArrayRef<OMPClause *> Clauses = D->clauses();
7127 TClauses.reserve(Clauses.size());
7128 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7129 I != E; ++I) {
7130 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007131 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007132 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007133 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007134 if (Clause)
7135 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007136 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007137 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007138 }
7139 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007140 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007141 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007142 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7143 /*CurScope=*/nullptr);
7144 StmtResult Body;
7145 {
7146 Sema::CompoundScopeRAII CompoundScope(getSema());
7147 Body = getDerived().TransformStmt(
7148 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7149 }
7150 AssociatedStmt =
7151 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007152 if (AssociatedStmt.isInvalid()) {
7153 return StmtError();
7154 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007155 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007156 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007157 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007158 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007159
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007160 // Transform directive name for 'omp critical' directive.
7161 DeclarationNameInfo DirName;
7162 if (D->getDirectiveKind() == OMPD_critical) {
7163 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7164 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7165 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007166 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7167 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7168 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007169 } else if (D->getDirectiveKind() == OMPD_cancel) {
7170 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007171 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007172
Alexander Musman64d33f12014-06-04 07:53:32 +00007173 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007174 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7175 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007176}
7177
Alexander Musman64d33f12014-06-04 07:53:32 +00007178template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007179StmtResult
7180TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7181 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007182 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7183 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007184 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7185 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7186 return Res;
7187}
7188
Alexander Musman64d33f12014-06-04 07:53:32 +00007189template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007190StmtResult
7191TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7192 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007193 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7194 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007195 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7196 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007197 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007198}
7199
Alexey Bataevf29276e2014-06-18 04:14:57 +00007200template <typename Derived>
7201StmtResult
7202TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7203 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007204 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7205 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007206 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7207 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7208 return Res;
7209}
7210
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007211template <typename Derived>
7212StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007213TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7214 DeclarationNameInfo DirName;
7215 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7216 D->getLocStart());
7217 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7218 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7219 return Res;
7220}
7221
7222template <typename Derived>
7223StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007224TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7225 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007226 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7227 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007228 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7229 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7230 return Res;
7231}
7232
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007233template <typename Derived>
7234StmtResult
7235TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7236 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007237 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7238 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007239 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7240 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7241 return Res;
7242}
7243
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007244template <typename Derived>
7245StmtResult
7246TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7247 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007248 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7249 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007250 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7251 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7252 return Res;
7253}
7254
Alexey Bataev4acb8592014-07-07 13:01:15 +00007255template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007256StmtResult
7257TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7258 DeclarationNameInfo DirName;
7259 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7260 D->getLocStart());
7261 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7262 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7263 return Res;
7264}
7265
7266template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007267StmtResult
7268TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7269 getDerived().getSema().StartOpenMPDSABlock(
7270 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7271 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7272 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7273 return Res;
7274}
7275
7276template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007277StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7278 OMPParallelForDirective *D) {
7279 DeclarationNameInfo DirName;
7280 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7281 nullptr, D->getLocStart());
7282 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7283 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7284 return Res;
7285}
7286
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007287template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007288StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7289 OMPParallelForSimdDirective *D) {
7290 DeclarationNameInfo DirName;
7291 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7292 nullptr, D->getLocStart());
7293 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7294 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7295 return Res;
7296}
7297
7298template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007299StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7300 OMPParallelSectionsDirective *D) {
7301 DeclarationNameInfo DirName;
7302 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7303 nullptr, D->getLocStart());
7304 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7305 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7306 return Res;
7307}
7308
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007309template <typename Derived>
7310StmtResult
7311TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7312 DeclarationNameInfo DirName;
7313 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7314 D->getLocStart());
7315 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7316 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7317 return Res;
7318}
7319
Alexey Bataev68446b72014-07-18 07:47:19 +00007320template <typename Derived>
7321StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7322 OMPTaskyieldDirective *D) {
7323 DeclarationNameInfo DirName;
7324 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7325 D->getLocStart());
7326 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7327 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7328 return Res;
7329}
7330
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007331template <typename Derived>
7332StmtResult
7333TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7334 DeclarationNameInfo DirName;
7335 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7336 D->getLocStart());
7337 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7338 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7339 return Res;
7340}
7341
Alexey Bataev2df347a2014-07-18 10:17:07 +00007342template <typename Derived>
7343StmtResult
7344TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7345 DeclarationNameInfo DirName;
7346 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7347 D->getLocStart());
7348 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7349 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7350 return Res;
7351}
7352
Alexey Bataev6125da92014-07-21 11:26:11 +00007353template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007354StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7355 OMPTaskgroupDirective *D) {
7356 DeclarationNameInfo DirName;
7357 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7358 D->getLocStart());
7359 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7360 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7361 return Res;
7362}
7363
7364template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007365StmtResult
7366TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7367 DeclarationNameInfo DirName;
7368 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7369 D->getLocStart());
7370 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7371 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7372 return Res;
7373}
7374
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007375template <typename Derived>
7376StmtResult
7377TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7378 DeclarationNameInfo DirName;
7379 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7380 D->getLocStart());
7381 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7382 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7383 return Res;
7384}
7385
Alexey Bataev0162e452014-07-22 10:10:35 +00007386template <typename Derived>
7387StmtResult
7388TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7389 DeclarationNameInfo DirName;
7390 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7391 D->getLocStart());
7392 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7393 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7394 return Res;
7395}
7396
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007397template <typename Derived>
7398StmtResult
7399TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7400 DeclarationNameInfo DirName;
7401 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7402 D->getLocStart());
7403 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7404 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7405 return Res;
7406}
7407
Alexey Bataev13314bf2014-10-09 04:18:56 +00007408template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007409StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7410 OMPTargetDataDirective *D) {
7411 DeclarationNameInfo DirName;
7412 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7413 D->getLocStart());
7414 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7415 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7416 return Res;
7417}
7418
7419template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007420StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7421 OMPTargetEnterDataDirective *D) {
7422 DeclarationNameInfo DirName;
7423 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_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>
Samuel Antao72590762016-01-19 20:04:50 +00007431StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7432 OMPTargetExitDataDirective *D) {
7433 DeclarationNameInfo DirName;
7434 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, 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 Jacobe955b3d2016-01-26 18:48:41 +00007442StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7443 OMPTargetParallelDirective *D) {
7444 DeclarationNameInfo DirName;
7445 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, 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>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007453StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7454 OMPTargetParallelForDirective *D) {
7455 DeclarationNameInfo DirName;
7456 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, 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>
Samuel Antao686c70c2016-05-26 17:30:50 +00007464StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7465 OMPTargetUpdateDirective *D) {
7466 DeclarationNameInfo DirName;
7467 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7468 nullptr, D->getLocStart());
7469 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7470 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7471 return Res;
7472}
7473
7474template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007475StmtResult
7476TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7477 DeclarationNameInfo DirName;
7478 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7479 D->getLocStart());
7480 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7481 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7482 return Res;
7483}
7484
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007485template <typename Derived>
7486StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7487 OMPCancellationPointDirective *D) {
7488 DeclarationNameInfo DirName;
7489 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7490 nullptr, D->getLocStart());
7491 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7492 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7493 return Res;
7494}
7495
Alexey Bataev80909872015-07-02 11:25:17 +00007496template <typename Derived>
7497StmtResult
7498TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7499 DeclarationNameInfo DirName;
7500 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7501 D->getLocStart());
7502 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7503 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7504 return Res;
7505}
7506
Alexey Bataev49f6e782015-12-01 04:18:41 +00007507template <typename Derived>
7508StmtResult
7509TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7510 DeclarationNameInfo DirName;
7511 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7512 D->getLocStart());
7513 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7514 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7515 return Res;
7516}
7517
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007518template <typename Derived>
7519StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7520 OMPTaskLoopSimdDirective *D) {
7521 DeclarationNameInfo DirName;
7522 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7523 nullptr, D->getLocStart());
7524 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7525 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7526 return Res;
7527}
7528
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007529template <typename Derived>
7530StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7531 OMPDistributeDirective *D) {
7532 DeclarationNameInfo DirName;
7533 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7534 D->getLocStart());
7535 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7536 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7537 return Res;
7538}
7539
Carlo Bertolli9925f152016-06-27 14:55:37 +00007540template <typename Derived>
7541StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7542 OMPDistributeParallelForDirective *D) {
7543 DeclarationNameInfo DirName;
7544 getDerived().getSema().StartOpenMPDSABlock(
7545 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7546 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7547 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7548 return Res;
7549}
7550
Kelvin Li4a39add2016-07-05 05:00:15 +00007551template <typename Derived>
7552StmtResult
7553TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7554 OMPDistributeParallelForSimdDirective *D) {
7555 DeclarationNameInfo DirName;
7556 getDerived().getSema().StartOpenMPDSABlock(
7557 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7560 return Res;
7561}
7562
Alexander Musman64d33f12014-06-04 07:53:32 +00007563//===----------------------------------------------------------------------===//
7564// OpenMP clause transformation
7565//===----------------------------------------------------------------------===//
7566template <typename Derived>
7567OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007568 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7569 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007570 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007571 return getDerived().RebuildOMPIfClause(
7572 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7573 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007574}
7575
Alexander Musman64d33f12014-06-04 07:53:32 +00007576template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007577OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7578 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7579 if (Cond.isInvalid())
7580 return nullptr;
7581 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7582 C->getLParenLoc(), C->getLocEnd());
7583}
7584
7585template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007586OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007587TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7588 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7589 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007590 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007591 return getDerived().RebuildOMPNumThreadsClause(
7592 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007593}
7594
Alexey Bataev62c87d22014-03-21 04:51:18 +00007595template <typename Derived>
7596OMPClause *
7597TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7598 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7599 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007600 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007601 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007602 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007603}
7604
Alexander Musman8bd31e62014-05-27 15:12:19 +00007605template <typename Derived>
7606OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007607TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7608 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7609 if (E.isInvalid())
7610 return nullptr;
7611 return getDerived().RebuildOMPSimdlenClause(
7612 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7613}
7614
7615template <typename Derived>
7616OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007617TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7618 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7619 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007620 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007621 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007622 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007623}
7624
Alexander Musman64d33f12014-06-04 07:53:32 +00007625template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007626OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007627TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007628 return getDerived().RebuildOMPDefaultClause(
7629 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7630 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007631}
7632
Alexander Musman64d33f12014-06-04 07:53:32 +00007633template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007634OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007635TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007636 return getDerived().RebuildOMPProcBindClause(
7637 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7638 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007639}
7640
Alexander Musman64d33f12014-06-04 07:53:32 +00007641template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007642OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007643TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7644 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7645 if (E.isInvalid())
7646 return nullptr;
7647 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007648 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007649 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007650 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007651 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7652}
7653
7654template <typename Derived>
7655OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007656TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007657 ExprResult E;
7658 if (auto *Num = C->getNumForLoops()) {
7659 E = getDerived().TransformExpr(Num);
7660 if (E.isInvalid())
7661 return nullptr;
7662 }
7663 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7664 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007665}
7666
7667template <typename Derived>
7668OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007669TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7670 // No need to rebuild this clause, no template-dependent parameters.
7671 return C;
7672}
7673
7674template <typename Derived>
7675OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007676TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7677 // No need to rebuild this clause, no template-dependent parameters.
7678 return C;
7679}
7680
7681template <typename Derived>
7682OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007683TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7684 // No need to rebuild this clause, no template-dependent parameters.
7685 return C;
7686}
7687
7688template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007689OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7690 // No need to rebuild this clause, no template-dependent parameters.
7691 return C;
7692}
7693
7694template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007695OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7696 // No need to rebuild this clause, no template-dependent parameters.
7697 return C;
7698}
7699
7700template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007701OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007702TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7703 // No need to rebuild this clause, no template-dependent parameters.
7704 return C;
7705}
7706
7707template <typename Derived>
7708OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007709TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7710 // No need to rebuild this clause, no template-dependent parameters.
7711 return C;
7712}
7713
7714template <typename Derived>
7715OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007716TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7717 // No need to rebuild this clause, no template-dependent parameters.
7718 return C;
7719}
7720
7721template <typename Derived>
7722OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007723TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7724 // No need to rebuild this clause, no template-dependent parameters.
7725 return C;
7726}
7727
7728template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007729OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7730 // No need to rebuild this clause, no template-dependent parameters.
7731 return C;
7732}
7733
7734template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007735OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007736TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7737 // No need to rebuild this clause, no template-dependent parameters.
7738 return C;
7739}
7740
7741template <typename Derived>
7742OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007743TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007744 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007745 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007746 for (auto *VE : C->varlists()) {
7747 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007748 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007749 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007750 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007751 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007752 return getDerived().RebuildOMPPrivateClause(
7753 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007754}
7755
Alexander Musman64d33f12014-06-04 07:53:32 +00007756template <typename Derived>
7757OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7758 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007759 llvm::SmallVector<Expr *, 16> Vars;
7760 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007761 for (auto *VE : C->varlists()) {
7762 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007763 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007764 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007765 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007766 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007767 return getDerived().RebuildOMPFirstprivateClause(
7768 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007769}
7770
Alexander Musman64d33f12014-06-04 07:53:32 +00007771template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007772OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007773TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7774 llvm::SmallVector<Expr *, 16> Vars;
7775 Vars.reserve(C->varlist_size());
7776 for (auto *VE : C->varlists()) {
7777 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7778 if (EVar.isInvalid())
7779 return nullptr;
7780 Vars.push_back(EVar.get());
7781 }
7782 return getDerived().RebuildOMPLastprivateClause(
7783 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7784}
7785
7786template <typename Derived>
7787OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007788TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7789 llvm::SmallVector<Expr *, 16> Vars;
7790 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007791 for (auto *VE : C->varlists()) {
7792 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007793 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007794 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007795 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007796 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007797 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7798 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007799}
7800
Alexander Musman64d33f12014-06-04 07:53:32 +00007801template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007802OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007803TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7804 llvm::SmallVector<Expr *, 16> Vars;
7805 Vars.reserve(C->varlist_size());
7806 for (auto *VE : C->varlists()) {
7807 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7808 if (EVar.isInvalid())
7809 return nullptr;
7810 Vars.push_back(EVar.get());
7811 }
7812 CXXScopeSpec ReductionIdScopeSpec;
7813 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7814
7815 DeclarationNameInfo NameInfo = C->getNameInfo();
7816 if (NameInfo.getName()) {
7817 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7818 if (!NameInfo.getName())
7819 return nullptr;
7820 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007821 // Build a list of all UDR decls with the same names ranged by the Scopes.
7822 // The Scope boundary is a duplication of the previous decl.
7823 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7824 for (auto *E : C->reduction_ops()) {
7825 // Transform all the decls.
7826 if (E) {
7827 auto *ULE = cast<UnresolvedLookupExpr>(E);
7828 UnresolvedSet<8> Decls;
7829 for (auto *D : ULE->decls()) {
7830 NamedDecl *InstD =
7831 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7832 Decls.addDecl(InstD, InstD->getAccess());
7833 }
7834 UnresolvedReductions.push_back(
7835 UnresolvedLookupExpr::Create(
7836 SemaRef.Context, /*NamingClass=*/nullptr,
7837 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7838 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7839 Decls.begin(), Decls.end()));
7840 } else
7841 UnresolvedReductions.push_back(nullptr);
7842 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007843 return getDerived().RebuildOMPReductionClause(
7844 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007845 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007846}
7847
7848template <typename Derived>
7849OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007850TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7851 llvm::SmallVector<Expr *, 16> Vars;
7852 Vars.reserve(C->varlist_size());
7853 for (auto *VE : C->varlists()) {
7854 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7855 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007856 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007857 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007858 }
7859 ExprResult Step = getDerived().TransformExpr(C->getStep());
7860 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007861 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007862 return getDerived().RebuildOMPLinearClause(
7863 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7864 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007865}
7866
Alexander Musman64d33f12014-06-04 07:53:32 +00007867template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007868OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007869TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7870 llvm::SmallVector<Expr *, 16> Vars;
7871 Vars.reserve(C->varlist_size());
7872 for (auto *VE : C->varlists()) {
7873 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7874 if (EVar.isInvalid())
7875 return nullptr;
7876 Vars.push_back(EVar.get());
7877 }
7878 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7879 if (Alignment.isInvalid())
7880 return nullptr;
7881 return getDerived().RebuildOMPAlignedClause(
7882 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7883 C->getColonLoc(), C->getLocEnd());
7884}
7885
Alexander Musman64d33f12014-06-04 07:53:32 +00007886template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007887OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007888TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7889 llvm::SmallVector<Expr *, 16> Vars;
7890 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007891 for (auto *VE : C->varlists()) {
7892 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007893 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007894 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007895 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007896 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007897 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7898 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007899}
7900
Alexey Bataevbae9a792014-06-27 10:37:06 +00007901template <typename Derived>
7902OMPClause *
7903TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7904 llvm::SmallVector<Expr *, 16> Vars;
7905 Vars.reserve(C->varlist_size());
7906 for (auto *VE : C->varlists()) {
7907 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7908 if (EVar.isInvalid())
7909 return nullptr;
7910 Vars.push_back(EVar.get());
7911 }
7912 return getDerived().RebuildOMPCopyprivateClause(
7913 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7914}
7915
Alexey Bataev6125da92014-07-21 11:26:11 +00007916template <typename Derived>
7917OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7918 llvm::SmallVector<Expr *, 16> Vars;
7919 Vars.reserve(C->varlist_size());
7920 for (auto *VE : C->varlists()) {
7921 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7922 if (EVar.isInvalid())
7923 return nullptr;
7924 Vars.push_back(EVar.get());
7925 }
7926 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7927 C->getLParenLoc(), C->getLocEnd());
7928}
7929
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007930template <typename Derived>
7931OMPClause *
7932TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7933 llvm::SmallVector<Expr *, 16> Vars;
7934 Vars.reserve(C->varlist_size());
7935 for (auto *VE : C->varlists()) {
7936 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7937 if (EVar.isInvalid())
7938 return nullptr;
7939 Vars.push_back(EVar.get());
7940 }
7941 return getDerived().RebuildOMPDependClause(
7942 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7943 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7944}
7945
Michael Wonge710d542015-08-07 16:16:36 +00007946template <typename Derived>
7947OMPClause *
7948TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7949 ExprResult E = getDerived().TransformExpr(C->getDevice());
7950 if (E.isInvalid())
7951 return nullptr;
7952 return getDerived().RebuildOMPDeviceClause(
7953 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7954}
7955
Kelvin Li0bff7af2015-11-23 05:32:03 +00007956template <typename Derived>
7957OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7958 llvm::SmallVector<Expr *, 16> Vars;
7959 Vars.reserve(C->varlist_size());
7960 for (auto *VE : C->varlists()) {
7961 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7962 if (EVar.isInvalid())
7963 return nullptr;
7964 Vars.push_back(EVar.get());
7965 }
7966 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00007967 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
7968 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
7969 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00007970}
7971
Kelvin Li099bb8c2015-11-24 20:50:12 +00007972template <typename Derived>
7973OMPClause *
7974TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7975 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7976 if (E.isInvalid())
7977 return nullptr;
7978 return getDerived().RebuildOMPNumTeamsClause(
7979 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7980}
7981
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007982template <typename Derived>
7983OMPClause *
7984TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7985 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7986 if (E.isInvalid())
7987 return nullptr;
7988 return getDerived().RebuildOMPThreadLimitClause(
7989 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7990}
7991
Alexey Bataeva0569352015-12-01 10:17:31 +00007992template <typename Derived>
7993OMPClause *
7994TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7995 ExprResult E = getDerived().TransformExpr(C->getPriority());
7996 if (E.isInvalid())
7997 return nullptr;
7998 return getDerived().RebuildOMPPriorityClause(
7999 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8000}
8001
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008002template <typename Derived>
8003OMPClause *
8004TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8005 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8006 if (E.isInvalid())
8007 return nullptr;
8008 return getDerived().RebuildOMPGrainsizeClause(
8009 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8010}
8011
Alexey Bataev382967a2015-12-08 12:06:20 +00008012template <typename Derived>
8013OMPClause *
8014TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8015 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8016 if (E.isInvalid())
8017 return nullptr;
8018 return getDerived().RebuildOMPNumTasksClause(
8019 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8020}
8021
Alexey Bataev28c75412015-12-15 08:19:24 +00008022template <typename Derived>
8023OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8024 ExprResult E = getDerived().TransformExpr(C->getHint());
8025 if (E.isInvalid())
8026 return nullptr;
8027 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8028 C->getLParenLoc(), C->getLocEnd());
8029}
8030
Carlo Bertollib4adf552016-01-15 18:50:31 +00008031template <typename Derived>
8032OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8033 OMPDistScheduleClause *C) {
8034 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8035 if (E.isInvalid())
8036 return nullptr;
8037 return getDerived().RebuildOMPDistScheduleClause(
8038 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8039 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8040}
8041
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008042template <typename Derived>
8043OMPClause *
8044TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8045 return C;
8046}
8047
Samuel Antao661c0902016-05-26 17:39:58 +00008048template <typename Derived>
8049OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8050 llvm::SmallVector<Expr *, 16> Vars;
8051 Vars.reserve(C->varlist_size());
8052 for (auto *VE : C->varlists()) {
8053 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8054 if (EVar.isInvalid())
8055 return 0;
8056 Vars.push_back(EVar.get());
8057 }
8058 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8059 C->getLParenLoc(), C->getLocEnd());
8060}
8061
Samuel Antaoec172c62016-05-26 17:49:04 +00008062template <typename Derived>
8063OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8064 llvm::SmallVector<Expr *, 16> Vars;
8065 Vars.reserve(C->varlist_size());
8066 for (auto *VE : C->varlists()) {
8067 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8068 if (EVar.isInvalid())
8069 return 0;
8070 Vars.push_back(EVar.get());
8071 }
8072 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8073 C->getLParenLoc(), C->getLocEnd());
8074}
8075
Douglas Gregorebe10102009-08-20 07:17:43 +00008076//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008077// Expression transformation
8078//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008080ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008081TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008082 if (!E->isTypeDependent())
8083 return E;
8084
8085 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8086 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008087}
Mike Stump11289f42009-09-09 15:08:12 +00008088
8089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008091TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008092 NestedNameSpecifierLoc QualifierLoc;
8093 if (E->getQualifierLoc()) {
8094 QualifierLoc
8095 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8096 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008097 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008098 }
John McCallce546572009-12-08 09:08:17 +00008099
8100 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008101 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8102 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008103 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008105
John McCall815039a2010-08-17 21:27:17 +00008106 DeclarationNameInfo NameInfo = E->getNameInfo();
8107 if (NameInfo.getName()) {
8108 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8109 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008111 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008112
8113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008114 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008115 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008116 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008117 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008118
8119 // Mark it referenced in the new context regardless.
8120 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008121 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008122
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008123 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008124 }
John McCallce546572009-12-08 09:08:17 +00008125
Craig Topperc3ec1492014-05-26 06:22:03 +00008126 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008127 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008128 TemplateArgs = &TransArgs;
8129 TransArgs.setLAngleLoc(E->getLAngleLoc());
8130 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008131 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8132 E->getNumTemplateArgs(),
8133 TransArgs))
8134 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008135 }
8136
Chad Rosier1dcde962012-08-08 18:46:20 +00008137 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008138 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008139}
Mike Stump11289f42009-09-09 15:08:12 +00008140
Douglas Gregora16548e2009-08-11 05:31:07 +00008141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008143TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008144 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008145}
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008149TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008150 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008151}
Mike Stump11289f42009-09-09 15:08:12 +00008152
Douglas Gregora16548e2009-08-11 05:31:07 +00008153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008155TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008156 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008157}
Mike Stump11289f42009-09-09 15:08:12 +00008158
Douglas Gregora16548e2009-08-11 05:31:07 +00008159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008161TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008162 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008163}
Mike Stump11289f42009-09-09 15:08:12 +00008164
Douglas Gregora16548e2009-08-11 05:31:07 +00008165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008167TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008168 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008169}
8170
8171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008172ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008173TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008174 if (FunctionDecl *FD = E->getDirectCallee())
8175 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008176 return SemaRef.MaybeBindToTemporary(E);
8177}
8178
8179template<typename Derived>
8180ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008181TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8182 ExprResult ControllingExpr =
8183 getDerived().TransformExpr(E->getControllingExpr());
8184 if (ControllingExpr.isInvalid())
8185 return ExprError();
8186
Chris Lattner01cf8db2011-07-20 06:58:45 +00008187 SmallVector<Expr *, 4> AssocExprs;
8188 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008189 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8190 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8191 if (TS) {
8192 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8193 if (!AssocType)
8194 return ExprError();
8195 AssocTypes.push_back(AssocType);
8196 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008197 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008198 }
8199
8200 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8201 if (AssocExpr.isInvalid())
8202 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008203 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008204 }
8205
8206 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8207 E->getDefaultLoc(),
8208 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008209 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008210 AssocTypes,
8211 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008212}
8213
8214template<typename Derived>
8215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008216TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008217 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008218 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008220
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008222 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008223
John McCallb268a282010-08-23 23:25:46 +00008224 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 E->getRParen());
8226}
8227
Richard Smithdb2630f2012-10-21 03:28:35 +00008228/// \brief The operand of a unary address-of operator has special rules: it's
8229/// allowed to refer to a non-static member of a class even if there's no 'this'
8230/// object available.
8231template<typename Derived>
8232ExprResult
8233TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8234 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008235 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008236 else
8237 return getDerived().TransformExpr(E);
8238}
8239
Mike Stump11289f42009-09-09 15:08:12 +00008240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008242TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008243 ExprResult SubExpr;
8244 if (E->getOpcode() == UO_AddrOf)
8245 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8246 else
8247 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregora16548e2009-08-11 05:31:07 +00008251 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008252 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008253
Douglas Gregora16548e2009-08-11 05:31:07 +00008254 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8255 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008256 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008257}
Mike Stump11289f42009-09-09 15:08:12 +00008258
Douglas Gregora16548e2009-08-11 05:31:07 +00008259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008260ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008261TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8262 // Transform the type.
8263 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8264 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008265 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008266
Douglas Gregor882211c2010-04-28 22:16:22 +00008267 // Transform all of the components into components similar to what the
8268 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008269 // FIXME: It would be slightly more efficient in the non-dependent case to
8270 // just map FieldDecls, rather than requiring the rebuilder to look for
8271 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008272 // template code that we don't care.
8273 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008274 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008275 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008276 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008277 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008278 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008279 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008280 Comp.LocStart = ON.getSourceRange().getBegin();
8281 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008282 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008283 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008284 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008285 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008286 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008288
Douglas Gregor882211c2010-04-28 22:16:22 +00008289 ExprChanged = ExprChanged || Index.get() != FromIndex;
8290 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008291 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008292 break;
8293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008294
James Y Knight7281c352015-12-29 22:31:18 +00008295 case OffsetOfNode::Field:
8296 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008297 Comp.isBrackets = false;
8298 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008299 if (!Comp.U.IdentInfo)
8300 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008301
Douglas Gregor882211c2010-04-28 22:16:22 +00008302 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008303
James Y Knight7281c352015-12-29 22:31:18 +00008304 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008305 // Will be recomputed during the rebuild.
8306 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008308
Douglas Gregor882211c2010-04-28 22:16:22 +00008309 Components.push_back(Comp);
8310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008311
Douglas Gregor882211c2010-04-28 22:16:22 +00008312 // If nothing changed, retain the existing expression.
8313 if (!getDerived().AlwaysRebuild() &&
8314 Type == E->getTypeSourceInfo() &&
8315 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008316 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008317
Douglas Gregor882211c2010-04-28 22:16:22 +00008318 // Build a new offsetof expression.
8319 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008320 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008321}
8322
8323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008324ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008325TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008326 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008327 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008328 return E;
John McCall8d69a212010-11-15 23:31:06 +00008329}
8330
8331template<typename Derived>
8332ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008333TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8334 return E;
8335}
8336
8337template<typename Derived>
8338ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008339TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008340 // Rebuild the syntactic form. The original syntactic form has
8341 // opaque-value expressions in it, so strip those away and rebuild
8342 // the result. This is a really awful way of doing this, but the
8343 // better solution (rebuilding the semantic expressions and
8344 // rebinding OVEs as necessary) doesn't work; we'd need
8345 // TreeTransform to not strip away implicit conversions.
8346 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8347 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008348 if (result.isInvalid()) return ExprError();
8349
8350 // If that gives us a pseudo-object result back, the pseudo-object
8351 // expression must have been an lvalue-to-rvalue conversion which we
8352 // should reapply.
8353 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008354 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008355
8356 return result;
8357}
8358
8359template<typename Derived>
8360ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008361TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8362 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008363 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008364 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008365
John McCallbcd03502009-12-07 02:54:59 +00008366 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008367 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008369
John McCall4c98fd82009-11-04 07:28:41 +00008370 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008371 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008372
Peter Collingbournee190dee2011-03-11 19:24:49 +00008373 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8374 E->getKind(),
8375 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008376 }
Mike Stump11289f42009-09-09 15:08:12 +00008377
Eli Friedmane4f22df2012-02-29 04:03:55 +00008378 // C++0x [expr.sizeof]p1:
8379 // The operand is either an expression, which is an unevaluated operand
8380 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8382 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008383
Reid Kleckner32506ed2014-06-12 23:03:48 +00008384 // Try to recover if we have something like sizeof(T::X) where X is a type.
8385 // Notably, there must be *exactly* one set of parens if X is a type.
8386 TypeSourceInfo *RecoveryTSI = nullptr;
8387 ExprResult SubExpr;
8388 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8389 if (auto *DRE =
8390 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8391 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8392 PE, DRE, false, &RecoveryTSI);
8393 else
8394 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8395
8396 if (RecoveryTSI) {
8397 return getDerived().RebuildUnaryExprOrTypeTrait(
8398 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8399 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008401
Eli Friedmane4f22df2012-02-29 04:03:55 +00008402 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008403 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008404
Peter Collingbournee190dee2011-03-11 19:24:49 +00008405 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8406 E->getOperatorLoc(),
8407 E->getKind(),
8408 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008409}
Mike Stump11289f42009-09-09 15:08:12 +00008410
Douglas Gregora16548e2009-08-11 05:31:07 +00008411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008413TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008414 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008415 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008417
John McCalldadc5752010-08-24 06:29:42 +00008418 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008421
8422
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 if (!getDerived().AlwaysRebuild() &&
8424 LHS.get() == E->getLHS() &&
8425 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008426 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008427
John McCallb268a282010-08-23 23:25:46 +00008428 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008429 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008430 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 E->getRBracketLoc());
8432}
Mike Stump11289f42009-09-09 15:08:12 +00008433
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008434template <typename Derived>
8435ExprResult
8436TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8437 ExprResult Base = getDerived().TransformExpr(E->getBase());
8438 if (Base.isInvalid())
8439 return ExprError();
8440
8441 ExprResult LowerBound;
8442 if (E->getLowerBound()) {
8443 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8444 if (LowerBound.isInvalid())
8445 return ExprError();
8446 }
8447
8448 ExprResult Length;
8449 if (E->getLength()) {
8450 Length = getDerived().TransformExpr(E->getLength());
8451 if (Length.isInvalid())
8452 return ExprError();
8453 }
8454
8455 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8456 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8457 return E;
8458
8459 return getDerived().RebuildOMPArraySectionExpr(
8460 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8461 Length.get(), E->getRBracketLoc());
8462}
8463
Mike Stump11289f42009-09-09 15:08:12 +00008464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008466TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008467 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008468 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008469 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008470 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008471
8472 // Transform arguments.
8473 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008474 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008475 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008476 &ArgChanged))
8477 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008478
Douglas Gregora16548e2009-08-11 05:31:07 +00008479 if (!getDerived().AlwaysRebuild() &&
8480 Callee.get() == E->getCallee() &&
8481 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008482 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008483
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008485 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008486 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008487 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008488 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008489 E->getRParenLoc());
8490}
Mike Stump11289f42009-09-09 15:08:12 +00008491
8492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008494TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008495 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008496 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008498
Douglas Gregorea972d32011-02-28 21:54:11 +00008499 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008500 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008501 QualifierLoc
8502 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008503
Douglas Gregorea972d32011-02-28 21:54:11 +00008504 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008505 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008506 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008507 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008508
Eli Friedman2cfcef62009-12-04 06:40:45 +00008509 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008510 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8511 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008512 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008514
John McCall16df1e52010-03-30 21:47:33 +00008515 NamedDecl *FoundDecl = E->getFoundDecl();
8516 if (FoundDecl == E->getMemberDecl()) {
8517 FoundDecl = Member;
8518 } else {
8519 FoundDecl = cast_or_null<NamedDecl>(
8520 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8521 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008522 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008523 }
8524
Douglas Gregora16548e2009-08-11 05:31:07 +00008525 if (!getDerived().AlwaysRebuild() &&
8526 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008527 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008528 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008529 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008530 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008531
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008532 // Mark it referenced in the new context regardless.
8533 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008534 SemaRef.MarkMemberReferenced(E);
8535
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008536 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008537 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008538
John McCall6b51f282009-11-23 01:53:49 +00008539 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008540 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008541 TransArgs.setLAngleLoc(E->getLAngleLoc());
8542 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008543 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8544 E->getNumTemplateArgs(),
8545 TransArgs))
8546 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008548
Douglas Gregora16548e2009-08-11 05:31:07 +00008549 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008550 SourceLocation FakeOperatorLoc =
8551 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008552
John McCall38836f02010-01-15 08:34:02 +00008553 // FIXME: to do this check properly, we will need to preserve the
8554 // first-qualifier-in-scope here, just in case we had a dependent
8555 // base (and therefore couldn't do the check) and a
8556 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008557 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008558
John McCallb268a282010-08-23 23:25:46 +00008559 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008561 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008562 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008563 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008564 Member,
John McCall16df1e52010-03-30 21:47:33 +00008565 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008566 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008567 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008568 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008569}
Mike Stump11289f42009-09-09 15:08:12 +00008570
Douglas Gregora16548e2009-08-11 05:31:07 +00008571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008573TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008574 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008575 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008577
John McCalldadc5752010-08-24 06:29:42 +00008578 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008579 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008581
Douglas Gregora16548e2009-08-11 05:31:07 +00008582 if (!getDerived().AlwaysRebuild() &&
8583 LHS.get() == E->getLHS() &&
8584 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008585 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008586
Lang Hames5de91cc2012-10-02 04:45:10 +00008587 Sema::FPContractStateRAII FPContractState(getSema());
8588 getSema().FPFeatures.fp_contract = E->isFPContractable();
8589
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008591 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008592}
8593
Mike Stump11289f42009-09-09 15:08:12 +00008594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008595ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008596TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008597 CompoundAssignOperator *E) {
8598 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008599}
Mike Stump11289f42009-09-09 15:08:12 +00008600
Douglas Gregora16548e2009-08-11 05:31:07 +00008601template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008602ExprResult TreeTransform<Derived>::
8603TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8604 // Just rebuild the common and RHS expressions and see whether we
8605 // get any changes.
8606
8607 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8608 if (commonExpr.isInvalid())
8609 return ExprError();
8610
8611 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8612 if (rhs.isInvalid())
8613 return ExprError();
8614
8615 if (!getDerived().AlwaysRebuild() &&
8616 commonExpr.get() == e->getCommon() &&
8617 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008618 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008619
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008620 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008621 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008622 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008623 e->getColonLoc(),
8624 rhs.get());
8625}
8626
8627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008629TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008630 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008631 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008633
John McCalldadc5752010-08-24 06:29:42 +00008634 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008637
John McCalldadc5752010-08-24 06:29:42 +00008638 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642 if (!getDerived().AlwaysRebuild() &&
8643 Cond.get() == E->getCond() &&
8644 LHS.get() == E->getLHS() &&
8645 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008646 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008647
John McCallb268a282010-08-23 23:25:46 +00008648 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008649 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008650 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008651 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008652 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008653}
Mike Stump11289f42009-09-09 15:08:12 +00008654
8655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008657TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008658 // Implicit casts are eliminated during transformation, since they
8659 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008660 return getDerived().TransformExpr(E->getSubExprAsWritten());
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>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008666 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8667 if (!Type)
8668 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008669
John McCalldadc5752010-08-24 06:29:42 +00008670 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008671 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (SubExpr.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() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008676 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008678 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008679
John McCall97513962010-01-15 18:39:57 +00008680 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008681 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008683 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008684}
Mike Stump11289f42009-09-09 15:08:12 +00008685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008688TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008689 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8690 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8691 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008693
John McCalldadc5752010-08-24 06:29:42 +00008694 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008695 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008697
Douglas Gregora16548e2009-08-11 05:31:07 +00008698 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008699 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008701 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008702
John McCall5d7aa7f2010-01-19 22:33:45 +00008703 // Note: the expression type doesn't necessarily match the
8704 // type-as-written, but that's okay, because it should always be
8705 // derivable from the initializer.
8706
John McCalle15bbff2010-01-18 19:35:47 +00008707 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008708 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008709 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008710}
Mike Stump11289f42009-09-09 15:08:12 +00008711
Douglas Gregora16548e2009-08-11 05:31:07 +00008712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008714TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008715 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008716 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008718
Douglas Gregora16548e2009-08-11 05:31:07 +00008719 if (!getDerived().AlwaysRebuild() &&
8720 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008721 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008722
Douglas Gregora16548e2009-08-11 05:31:07 +00008723 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008724 SourceLocation FakeOperatorLoc =
8725 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008726 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008727 E->getAccessorLoc(),
8728 E->getAccessor());
8729}
Mike Stump11289f42009-09-09 15:08:12 +00008730
Douglas Gregora16548e2009-08-11 05:31:07 +00008731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008733TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008734 if (InitListExpr *Syntactic = E->getSyntacticForm())
8735 E = Syntactic;
8736
Douglas Gregora16548e2009-08-11 05:31:07 +00008737 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008738
Benjamin Kramerf0623432012-08-23 22:51:59 +00008739 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008740 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008741 Inits, &InitChanged))
8742 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008743
Richard Smith520449d2015-02-05 06:15:50 +00008744 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8745 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8746 // in some cases. We can't reuse it in general, because the syntactic and
8747 // semantic forms are linked, and we can't know that semantic form will
8748 // match even if the syntactic form does.
8749 }
Mike Stump11289f42009-09-09 15:08:12 +00008750
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008751 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008752 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008753}
Mike Stump11289f42009-09-09 15:08:12 +00008754
Douglas Gregora16548e2009-08-11 05:31:07 +00008755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008757TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008759
Douglas Gregorebe10102009-08-20 07:17:43 +00008760 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008761 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008762 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008764
Douglas Gregorebe10102009-08-20 07:17:43 +00008765 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008766 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008767 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008768 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8769 if (D.isFieldDesignator()) {
8770 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8771 D.getDotLoc(),
8772 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 continue;
8774 }
Mike Stump11289f42009-09-09 15:08:12 +00008775
David Majnemerf7e36092016-06-23 00:15:04 +00008776 if (D.isArrayDesignator()) {
8777 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008778 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008780
David Majnemerf7e36092016-06-23 00:15:04 +00008781 Desig.AddDesignator(
8782 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008783
David Majnemerf7e36092016-06-23 00:15:04 +00008784 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008785 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008786 continue;
8787 }
Mike Stump11289f42009-09-09 15:08:12 +00008788
David Majnemerf7e36092016-06-23 00:15:04 +00008789 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008790 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008791 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008792 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008794
David Majnemerf7e36092016-06-23 00:15:04 +00008795 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008796 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008798
8799 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008800 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008801 D.getLBracketLoc(),
8802 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008803
David Majnemerf7e36092016-06-23 00:15:04 +00008804 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8805 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008806
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008807 ArrayExprs.push_back(Start.get());
8808 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 }
Mike Stump11289f42009-09-09 15:08:12 +00008810
Douglas Gregora16548e2009-08-11 05:31:07 +00008811 if (!getDerived().AlwaysRebuild() &&
8812 Init.get() == E->getInit() &&
8813 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008814 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008815
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008816 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008818 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008819}
Mike Stump11289f42009-09-09 15:08:12 +00008820
Yunzhong Gaocb779302015-06-10 00:27:52 +00008821// Seems that if TransformInitListExpr() only works on the syntactic form of an
8822// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8823template<typename Derived>
8824ExprResult
8825TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8826 DesignatedInitUpdateExpr *E) {
8827 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8828 "initializer");
8829 return ExprError();
8830}
8831
8832template<typename Derived>
8833ExprResult
8834TreeTransform<Derived>::TransformNoInitExpr(
8835 NoInitExpr *E) {
8836 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8837 return ExprError();
8838}
8839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008841ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008842TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008843 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008844 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008845
Douglas Gregor3da3c062009-10-28 00:29:27 +00008846 // FIXME: Will we ever have proper type location here? Will we actually
8847 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 QualType T = getDerived().TransformType(E->getType());
8849 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008851
Douglas Gregora16548e2009-08-11 05:31:07 +00008852 if (!getDerived().AlwaysRebuild() &&
8853 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008854 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008855
Douglas Gregora16548e2009-08-11 05:31:07 +00008856 return getDerived().RebuildImplicitValueInitExpr(T);
8857}
Mike Stump11289f42009-09-09 15:08:12 +00008858
Douglas Gregora16548e2009-08-11 05:31:07 +00008859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008860ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008861TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008862 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8863 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008865
John McCalldadc5752010-08-24 06:29:42 +00008866 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008867 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008869
Douglas Gregora16548e2009-08-11 05:31:07 +00008870 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008871 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008873 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008874
John McCallb268a282010-08-23 23:25:46 +00008875 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008876 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008877}
8878
8879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008881TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008882 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008883 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008884 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8885 &ArgumentChanged))
8886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008887
Douglas Gregora16548e2009-08-11 05:31:07 +00008888 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008889 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008890 E->getRParenLoc());
8891}
Mike Stump11289f42009-09-09 15:08:12 +00008892
Douglas Gregora16548e2009-08-11 05:31:07 +00008893/// \brief Transform an address-of-label expression.
8894///
8895/// By default, the transformation of an address-of-label expression always
8896/// rebuilds the expression, so that the label identifier can be resolved to
8897/// the corresponding label statement by semantic analysis.
8898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008900TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008901 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8902 E->getLabel());
8903 if (!LD)
8904 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
Douglas Gregora16548e2009-08-11 05:31:07 +00008906 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008907 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
8910template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008912TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008913 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008914 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008915 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008916 if (SubStmt.isInvalid()) {
8917 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008918 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008919 }
Mike Stump11289f42009-09-09 15:08:12 +00008920
Douglas Gregora16548e2009-08-11 05:31:07 +00008921 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008922 SubStmt.get() == E->getSubStmt()) {
8923 // Calling this an 'error' is unintuitive, but it does the right thing.
8924 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008925 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008926 }
Mike Stump11289f42009-09-09 15:08:12 +00008927
8928 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008929 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008930 E->getRParenLoc());
8931}
Mike Stump11289f42009-09-09 15:08:12 +00008932
Douglas Gregora16548e2009-08-11 05:31:07 +00008933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008935TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008936 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008937 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008938 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008939
John McCalldadc5752010-08-24 06:29:42 +00008940 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008941 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008942 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008943
John McCalldadc5752010-08-24 06:29:42 +00008944 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008945 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008947
Douglas Gregora16548e2009-08-11 05:31:07 +00008948 if (!getDerived().AlwaysRebuild() &&
8949 Cond.get() == E->getCond() &&
8950 LHS.get() == E->getLHS() &&
8951 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008952 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008953
Douglas Gregora16548e2009-08-11 05:31:07 +00008954 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008955 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 E->getRParenLoc());
8957}
Mike Stump11289f42009-09-09 15:08:12 +00008958
Douglas Gregora16548e2009-08-11 05:31:07 +00008959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008961TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008962 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008963}
8964
8965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008967TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008968 switch (E->getOperator()) {
8969 case OO_New:
8970 case OO_Delete:
8971 case OO_Array_New:
8972 case OO_Array_Delete:
8973 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008974
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008975 case OO_Call: {
8976 // This is a call to an object's operator().
8977 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8978
8979 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008980 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008981 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008982 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008983
8984 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008985 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8986 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008987
8988 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008989 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008990 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008991 Args))
8992 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008993
John McCallb268a282010-08-23 23:25:46 +00008994 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008995 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008996 E->getLocEnd());
8997 }
8998
8999#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9000 case OO_##Name:
9001#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9002#include "clang/Basic/OperatorKinds.def"
9003 case OO_Subscript:
9004 // Handled below.
9005 break;
9006
9007 case OO_Conditional:
9008 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009009
9010 case OO_None:
9011 case NUM_OVERLOADED_OPERATORS:
9012 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009013 }
9014
John McCalldadc5752010-08-24 06:29:42 +00009015 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009016 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009018
Richard Smithdb2630f2012-10-21 03:28:35 +00009019 ExprResult First;
9020 if (E->getOperator() == OO_Amp)
9021 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9022 else
9023 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009024 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009025 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009026
John McCalldadc5752010-08-24 06:29:42 +00009027 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 if (E->getNumArgs() == 2) {
9029 Second = getDerived().TransformExpr(E->getArg(1));
9030 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009031 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009032 }
Mike Stump11289f42009-09-09 15:08:12 +00009033
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 if (!getDerived().AlwaysRebuild() &&
9035 Callee.get() == E->getCallee() &&
9036 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009037 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009038 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009039
Lang Hames5de91cc2012-10-02 04:45:10 +00009040 Sema::FPContractStateRAII FPContractState(getSema());
9041 getSema().FPFeatures.fp_contract = E->isFPContractable();
9042
Douglas Gregora16548e2009-08-11 05:31:07 +00009043 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9044 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009045 Callee.get(),
9046 First.get(),
9047 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009048}
Mike Stump11289f42009-09-09 15:08:12 +00009049
Douglas Gregora16548e2009-08-11 05:31:07 +00009050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009052TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9053 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009054}
Mike Stump11289f42009-09-09 15:08:12 +00009055
Douglas Gregora16548e2009-08-11 05:31:07 +00009056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009057ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009058TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9059 // Transform the callee.
9060 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9061 if (Callee.isInvalid())
9062 return ExprError();
9063
9064 // Transform exec config.
9065 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9066 if (EC.isInvalid())
9067 return ExprError();
9068
9069 // Transform arguments.
9070 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009071 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009072 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009073 &ArgChanged))
9074 return ExprError();
9075
9076 if (!getDerived().AlwaysRebuild() &&
9077 Callee.get() == E->getCallee() &&
9078 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009079 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009080
9081 // FIXME: Wrong source location information for the '('.
9082 SourceLocation FakeLParenLoc
9083 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9084 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009085 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009086 E->getRParenLoc(), EC.get());
9087}
9088
9089template<typename Derived>
9090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009092 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9093 if (!Type)
9094 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
John McCalldadc5752010-08-24 06:29:42 +00009096 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009097 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009098 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009100
Douglas Gregora16548e2009-08-11 05:31:07 +00009101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009102 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009103 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009104 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009105 return getDerived().RebuildCXXNamedCastExpr(
9106 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9107 Type, E->getAngleBrackets().getEnd(),
9108 // FIXME. this should be '(' location
9109 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009110}
Mike Stump11289f42009-09-09 15:08:12 +00009111
Douglas Gregora16548e2009-08-11 05:31:07 +00009112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009114TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9115 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009116}
Mike Stump11289f42009-09-09 15:08:12 +00009117
9118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009120TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9121 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009122}
9123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009125ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009126TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009127 CXXReinterpretCastExpr *E) {
9128 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009129}
Mike Stump11289f42009-09-09 15:08:12 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009133TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9134 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009135}
Mike Stump11289f42009-09-09 15:08:12 +00009136
Douglas Gregora16548e2009-08-11 05:31:07 +00009137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009138ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009139TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009140 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009141 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9142 if (!Type)
9143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009144
John McCalldadc5752010-08-24 06:29:42 +00009145 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009146 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009147 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009149
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009151 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009152 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009153 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009154
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009155 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009156 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009157 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009158 E->getRParenLoc());
9159}
Mike Stump11289f42009-09-09 15:08:12 +00009160
Douglas Gregora16548e2009-08-11 05:31:07 +00009161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009163TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009164 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009165 TypeSourceInfo *TInfo
9166 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9167 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009169
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009171 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009172 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009173
Douglas Gregor9da64192010-04-26 22:37:10 +00009174 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9175 E->getLocStart(),
9176 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009177 E->getLocEnd());
9178 }
Mike Stump11289f42009-09-09 15:08:12 +00009179
Eli Friedman456f0182012-01-20 01:26:23 +00009180 // We don't know whether the subexpression is potentially evaluated until
9181 // after we perform semantic analysis. We speculatively assume it is
9182 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009183 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009184 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9185 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009186
John McCalldadc5752010-08-24 06:29:42 +00009187 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009188 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009190
Douglas Gregora16548e2009-08-11 05:31:07 +00009191 if (!getDerived().AlwaysRebuild() &&
9192 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009193 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009194
Douglas Gregor9da64192010-04-26 22:37:10 +00009195 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9196 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009197 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009198 E->getLocEnd());
9199}
9200
9201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009202ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009203TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9204 if (E->isTypeOperand()) {
9205 TypeSourceInfo *TInfo
9206 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9207 if (!TInfo)
9208 return ExprError();
9209
9210 if (!getDerived().AlwaysRebuild() &&
9211 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009212 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009213
Douglas Gregor69735112011-03-06 17:40:41 +00009214 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009215 E->getLocStart(),
9216 TInfo,
9217 E->getLocEnd());
9218 }
9219
Francois Pichet9f4f2072010-09-08 12:20:18 +00009220 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9221
9222 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9223 if (SubExpr.isInvalid())
9224 return ExprError();
9225
9226 if (!getDerived().AlwaysRebuild() &&
9227 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009228 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009229
9230 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9231 E->getLocStart(),
9232 SubExpr.get(),
9233 E->getLocEnd());
9234}
9235
9236template<typename Derived>
9237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009238TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009239 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009240}
Mike Stump11289f42009-09-09 15:08:12 +00009241
Douglas Gregora16548e2009-08-11 05:31:07 +00009242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009243ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009244TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009245 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009246 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009247}
Mike Stump11289f42009-09-09 15:08:12 +00009248
Douglas Gregora16548e2009-08-11 05:31:07 +00009249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009251TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009252 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009253
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009254 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9255 // Make sure that we capture 'this'.
9256 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009257 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009259
Douglas Gregorb15af892010-01-07 23:12:05 +00009260 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009261}
Mike Stump11289f42009-09-09 15:08:12 +00009262
Douglas Gregora16548e2009-08-11 05:31:07 +00009263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009265TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009266 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009267 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009269
Douglas Gregora16548e2009-08-11 05:31:07 +00009270 if (!getDerived().AlwaysRebuild() &&
9271 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009272 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009273
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009274 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9275 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009276}
Mike Stump11289f42009-09-09 15:08:12 +00009277
Douglas Gregora16548e2009-08-11 05:31:07 +00009278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009281 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009282 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9283 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009286
Chandler Carruth794da4c2010-02-08 06:42:49 +00009287 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009288 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009289 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009290
Douglas Gregor033f6752009-12-23 23:03:06 +00009291 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009292}
Mike Stump11289f42009-09-09 15:08:12 +00009293
Douglas Gregora16548e2009-08-11 05:31:07 +00009294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009295ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009296TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9297 FieldDecl *Field
9298 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9299 E->getField()));
9300 if (!Field)
9301 return ExprError();
9302
9303 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009304 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009305
9306 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9307}
9308
9309template<typename Derived>
9310ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009311TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9312 CXXScalarValueInitExpr *E) {
9313 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9314 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
Douglas Gregora16548e2009-08-11 05:31:07 +00009317 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009318 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009319 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009320
Chad Rosier1dcde962012-08-08 18:46:20 +00009321 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009322 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009323 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009324}
Mike Stump11289f42009-09-09 15:08:12 +00009325
Douglas Gregora16548e2009-08-11 05:31:07 +00009326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009328TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009330 TypeSourceInfo *AllocTypeInfo
9331 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9332 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009334
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009336 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009337 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009339
Douglas Gregora16548e2009-08-11 05:31:07 +00009340 // Transform the placement arguments (if any).
9341 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009342 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009343 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009344 E->getNumPlacementArgs(), true,
9345 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009347
Sebastian Redl6047f072012-02-16 12:22:20 +00009348 // Transform the initializer (if any).
9349 Expr *OldInit = E->getInitializer();
9350 ExprResult NewInit;
9351 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009352 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009353 if (NewInit.isInvalid())
9354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009355
Sebastian Redl6047f072012-02-16 12:22:20 +00009356 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009357 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009358 if (E->getOperatorNew()) {
9359 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009360 getDerived().TransformDecl(E->getLocStart(),
9361 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009362 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009363 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009364 }
9365
Craig Topperc3ec1492014-05-26 06:22:03 +00009366 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009367 if (E->getOperatorDelete()) {
9368 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009369 getDerived().TransformDecl(E->getLocStart(),
9370 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009371 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009372 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009374
Douglas Gregora16548e2009-08-11 05:31:07 +00009375 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009376 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009377 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009378 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009379 OperatorNew == E->getOperatorNew() &&
9380 OperatorDelete == E->getOperatorDelete() &&
9381 !ArgumentChanged) {
9382 // Mark any declarations we need as referenced.
9383 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009384 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009385 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009386 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009387 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009388
Sebastian Redl6047f072012-02-16 12:22:20 +00009389 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009390 QualType ElementType
9391 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9392 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9393 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9394 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009395 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009396 }
9397 }
9398 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009399
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009400 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009401 }
Mike Stump11289f42009-09-09 15:08:12 +00009402
Douglas Gregor0744ef62010-09-07 21:49:58 +00009403 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009404 if (!ArraySize.get()) {
9405 // If no array size was specified, but the new expression was
9406 // instantiated with an array type (e.g., "new T" where T is
9407 // instantiated with "int[4]"), extract the outer bound from the
9408 // array type as our array size. We do this with constant and
9409 // dependently-sized array types.
9410 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9411 if (!ArrayT) {
9412 // Do nothing
9413 } else if (const ConstantArrayType *ConsArrayT
9414 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009415 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9416 SemaRef.Context.getSizeType(),
9417 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009418 AllocType = ConsArrayT->getElementType();
9419 } else if (const DependentSizedArrayType *DepArrayT
9420 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9421 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009422 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009423 AllocType = DepArrayT->getElementType();
9424 }
9425 }
9426 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009427
Douglas Gregora16548e2009-08-11 05:31:07 +00009428 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9429 E->isGlobalNew(),
9430 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009431 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009432 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009433 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009434 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009435 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009436 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009437 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009438 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009439}
Mike Stump11289f42009-09-09 15:08:12 +00009440
Douglas Gregora16548e2009-08-11 05:31:07 +00009441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009443TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009444 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009445 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009447
Douglas Gregord2d9da02010-02-26 00:38:10 +00009448 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009449 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009450 if (E->getOperatorDelete()) {
9451 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009452 getDerived().TransformDecl(E->getLocStart(),
9453 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009454 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009455 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009457
Douglas Gregora16548e2009-08-11 05:31:07 +00009458 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009459 Operand.get() == E->getArgument() &&
9460 OperatorDelete == E->getOperatorDelete()) {
9461 // Mark any declarations we need as referenced.
9462 // FIXME: instantiation-specific.
9463 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009464 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009465
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009466 if (!E->getArgument()->isTypeDependent()) {
9467 QualType Destroyed = SemaRef.Context.getBaseElementType(
9468 E->getDestroyedType());
9469 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9470 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009471 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009472 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009473 }
9474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009475
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009476 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009477 }
Mike Stump11289f42009-09-09 15:08:12 +00009478
Douglas Gregora16548e2009-08-11 05:31:07 +00009479 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9480 E->isGlobalDelete(),
9481 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009482 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009483}
Mike Stump11289f42009-09-09 15:08:12 +00009484
Douglas Gregora16548e2009-08-11 05:31:07 +00009485template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009486ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009487TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009488 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009489 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009490 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009492
John McCallba7bf592010-08-24 05:47:05 +00009493 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009494 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009495 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009496 E->getOperatorLoc(),
9497 E->isArrow()? tok::arrow : tok::period,
9498 ObjectTypePtr,
9499 MayBePseudoDestructor);
9500 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009501 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009502
John McCallba7bf592010-08-24 05:47:05 +00009503 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009504 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9505 if (QualifierLoc) {
9506 QualifierLoc
9507 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9508 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009509 return ExprError();
9510 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009511 CXXScopeSpec SS;
9512 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009513
Douglas Gregor678f90d2010-02-25 01:56:36 +00009514 PseudoDestructorTypeStorage Destroyed;
9515 if (E->getDestroyedTypeInfo()) {
9516 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009517 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009518 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009519 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009520 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009521 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009522 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009523 // We aren't likely to be able to resolve the identifier down to a type
9524 // now anyway, so just retain the identifier.
9525 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9526 E->getDestroyedTypeLoc());
9527 } else {
9528 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009529 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009530 *E->getDestroyedTypeIdentifier(),
9531 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009532 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009533 SS, ObjectTypePtr,
9534 false);
9535 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009536 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009537
Douglas Gregor678f90d2010-02-25 01:56:36 +00009538 Destroyed
9539 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9540 E->getDestroyedTypeLoc());
9541 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009542
Craig Topperc3ec1492014-05-26 06:22:03 +00009543 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009544 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009545 CXXScopeSpec EmptySS;
9546 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009547 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009548 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009549 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009551
John McCallb268a282010-08-23 23:25:46 +00009552 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009553 E->getOperatorLoc(),
9554 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009555 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009556 ScopeTypeInfo,
9557 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009558 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009559 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009560}
Mike Stump11289f42009-09-09 15:08:12 +00009561
Douglas Gregorad8a3362009-09-04 17:36:40 +00009562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009563ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009564TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009565 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009566 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9567 Sema::LookupOrdinaryName);
9568
9569 // Transform all the decls.
9570 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9571 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009572 NamedDecl *InstD = static_cast<NamedDecl*>(
9573 getDerived().TransformDecl(Old->getNameLoc(),
9574 *I));
John McCall84d87672009-12-10 09:41:52 +00009575 if (!InstD) {
9576 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9577 // This can happen because of dependent hiding.
9578 if (isa<UsingShadowDecl>(*I))
9579 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009580 else {
9581 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009582 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009583 }
John McCall84d87672009-12-10 09:41:52 +00009584 }
John McCalle66edc12009-11-24 19:00:30 +00009585
9586 // Expand using declarations.
9587 if (isa<UsingDecl>(InstD)) {
9588 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009589 for (auto *I : UD->shadows())
9590 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009591 continue;
9592 }
9593
9594 R.addDecl(InstD);
9595 }
9596
9597 // Resolve a kind, but don't do any further analysis. If it's
9598 // ambiguous, the callee needs to deal with it.
9599 R.resolveKind();
9600
9601 // Rebuild the nested-name qualifier, if present.
9602 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009603 if (Old->getQualifierLoc()) {
9604 NestedNameSpecifierLoc QualifierLoc
9605 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9606 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009607 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009608
Douglas Gregor0da1d432011-02-28 20:01:57 +00009609 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009610 }
9611
Douglas Gregor9262f472010-04-27 18:19:34 +00009612 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009613 CXXRecordDecl *NamingClass
9614 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9615 Old->getNameLoc(),
9616 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009617 if (!NamingClass) {
9618 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009619 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009621
Douglas Gregorda7be082010-04-27 16:10:10 +00009622 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009623 }
9624
Abramo Bagnara7945c982012-01-27 09:46:47 +00009625 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9626
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009627 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009628 // it's a normal declaration name or member reference.
9629 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9630 NamedDecl *D = R.getAsSingle<NamedDecl>();
9631 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9632 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9633 // give a good diagnostic.
9634 if (D && D->isCXXInstanceMember()) {
9635 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9636 /*TemplateArgs=*/nullptr,
9637 /*Scope=*/nullptr);
9638 }
9639
John McCalle66edc12009-11-24 19:00:30 +00009640 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009641 }
John McCalle66edc12009-11-24 19:00:30 +00009642
9643 // If we have template arguments, rebuild them, then rebuild the
9644 // templateid expression.
9645 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009646 if (Old->hasExplicitTemplateArgs() &&
9647 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009648 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009649 TransArgs)) {
9650 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009651 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009652 }
John McCalle66edc12009-11-24 19:00:30 +00009653
Abramo Bagnara7945c982012-01-27 09:46:47 +00009654 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009655 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009656}
Mike Stump11289f42009-09-09 15:08:12 +00009657
Douglas Gregora16548e2009-08-11 05:31:07 +00009658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009659ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009660TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9661 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009662 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009663 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9664 TypeSourceInfo *From = E->getArg(I);
9665 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009666 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009667 TypeLocBuilder TLB;
9668 TLB.reserve(FromTL.getFullDataSize());
9669 QualType To = getDerived().TransformType(TLB, FromTL);
9670 if (To.isNull())
9671 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009672
Douglas Gregor29c42f22012-02-24 07:38:34 +00009673 if (To == From->getType())
9674 Args.push_back(From);
9675 else {
9676 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9677 ArgChanged = true;
9678 }
9679 continue;
9680 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009681
Douglas Gregor29c42f22012-02-24 07:38:34 +00009682 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009683
Douglas Gregor29c42f22012-02-24 07:38:34 +00009684 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009685 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009686 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9687 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9688 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009689
Douglas Gregor29c42f22012-02-24 07:38:34 +00009690 // Determine whether the set of unexpanded parameter packs can and should
9691 // be expanded.
9692 bool Expand = true;
9693 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009694 Optional<unsigned> OrigNumExpansions =
9695 ExpansionTL.getTypePtr()->getNumExpansions();
9696 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009697 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9698 PatternTL.getSourceRange(),
9699 Unexpanded,
9700 Expand, RetainExpansion,
9701 NumExpansions))
9702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009703
Douglas Gregor29c42f22012-02-24 07:38:34 +00009704 if (!Expand) {
9705 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009706 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009707 // expansion.
9708 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009709
Douglas Gregor29c42f22012-02-24 07:38:34 +00009710 TypeLocBuilder TLB;
9711 TLB.reserve(From->getTypeLoc().getFullDataSize());
9712
9713 QualType To = getDerived().TransformType(TLB, PatternTL);
9714 if (To.isNull())
9715 return ExprError();
9716
Chad Rosier1dcde962012-08-08 18:46:20 +00009717 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009718 PatternTL.getSourceRange(),
9719 ExpansionTL.getEllipsisLoc(),
9720 NumExpansions);
9721 if (To.isNull())
9722 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009723
Douglas Gregor29c42f22012-02-24 07:38:34 +00009724 PackExpansionTypeLoc ToExpansionTL
9725 = TLB.push<PackExpansionTypeLoc>(To);
9726 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9727 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9728 continue;
9729 }
9730
9731 // Expand the pack expansion by substituting for each argument in the
9732 // pack(s).
9733 for (unsigned I = 0; I != *NumExpansions; ++I) {
9734 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9735 TypeLocBuilder TLB;
9736 TLB.reserve(PatternTL.getFullDataSize());
9737 QualType To = getDerived().TransformType(TLB, PatternTL);
9738 if (To.isNull())
9739 return ExprError();
9740
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009741 if (To->containsUnexpandedParameterPack()) {
9742 To = getDerived().RebuildPackExpansionType(To,
9743 PatternTL.getSourceRange(),
9744 ExpansionTL.getEllipsisLoc(),
9745 NumExpansions);
9746 if (To.isNull())
9747 return ExprError();
9748
9749 PackExpansionTypeLoc ToExpansionTL
9750 = TLB.push<PackExpansionTypeLoc>(To);
9751 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9752 }
9753
Douglas Gregor29c42f22012-02-24 07:38:34 +00009754 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009756
Douglas Gregor29c42f22012-02-24 07:38:34 +00009757 if (!RetainExpansion)
9758 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009759
Douglas Gregor29c42f22012-02-24 07:38:34 +00009760 // If we're supposed to retain a pack expansion, do so by temporarily
9761 // forgetting the partially-substituted parameter pack.
9762 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9763
9764 TypeLocBuilder TLB;
9765 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009766
Douglas Gregor29c42f22012-02-24 07:38:34 +00009767 QualType To = getDerived().TransformType(TLB, PatternTL);
9768 if (To.isNull())
9769 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009770
9771 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009772 PatternTL.getSourceRange(),
9773 ExpansionTL.getEllipsisLoc(),
9774 NumExpansions);
9775 if (To.isNull())
9776 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009777
Douglas Gregor29c42f22012-02-24 07:38:34 +00009778 PackExpansionTypeLoc ToExpansionTL
9779 = TLB.push<PackExpansionTypeLoc>(To);
9780 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9781 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor29c42f22012-02-24 07:38:34 +00009784 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009785 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009786
9787 return getDerived().RebuildTypeTrait(E->getTrait(),
9788 E->getLocStart(),
9789 Args,
9790 E->getLocEnd());
9791}
9792
9793template<typename Derived>
9794ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009795TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9796 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9797 if (!T)
9798 return ExprError();
9799
9800 if (!getDerived().AlwaysRebuild() &&
9801 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009803
9804 ExprResult SubExpr;
9805 {
9806 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9807 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9808 if (SubExpr.isInvalid())
9809 return ExprError();
9810
9811 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009812 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009813 }
9814
9815 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9816 E->getLocStart(),
9817 T,
9818 SubExpr.get(),
9819 E->getLocEnd());
9820}
9821
9822template<typename Derived>
9823ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009824TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9825 ExprResult SubExpr;
9826 {
9827 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9828 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9829 if (SubExpr.isInvalid())
9830 return ExprError();
9831
9832 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009833 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009834 }
9835
9836 return getDerived().RebuildExpressionTrait(
9837 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9838}
9839
Reid Kleckner32506ed2014-06-12 23:03:48 +00009840template <typename Derived>
9841ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9842 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9843 TypeSourceInfo **RecoveryTSI) {
9844 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9845 DRE, AddrTaken, RecoveryTSI);
9846
9847 // Propagate both errors and recovered types, which return ExprEmpty.
9848 if (!NewDRE.isUsable())
9849 return NewDRE;
9850
9851 // We got an expr, wrap it up in parens.
9852 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9853 return PE;
9854 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9855 PE->getRParen());
9856}
9857
9858template <typename Derived>
9859ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9860 DependentScopeDeclRefExpr *E) {
9861 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9862 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009863}
9864
9865template<typename Derived>
9866ExprResult
9867TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9868 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009869 bool IsAddressOfOperand,
9870 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009871 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009872 NestedNameSpecifierLoc QualifierLoc
9873 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9874 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009875 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009876 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009877
John McCall31f82722010-11-12 08:19:04 +00009878 // TODO: If this is a conversion-function-id, verify that the
9879 // destination type name (if present) resolves the same way after
9880 // instantiation as it did in the local scope.
9881
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009882 DeclarationNameInfo NameInfo
9883 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9884 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009886
John McCalle66edc12009-11-24 19:00:30 +00009887 if (!E->hasExplicitTemplateArgs()) {
9888 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009889 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009890 // Note: it is sufficient to compare the Name component of NameInfo:
9891 // if name has not changed, DNLoc has not changed either.
9892 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009893 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009894
Reid Kleckner32506ed2014-06-12 23:03:48 +00009895 return getDerived().RebuildDependentScopeDeclRefExpr(
9896 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9897 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009898 }
John McCall6b51f282009-11-23 01:53:49 +00009899
9900 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009901 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9902 E->getNumTemplateArgs(),
9903 TransArgs))
9904 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009905
Reid Kleckner32506ed2014-06-12 23:03:48 +00009906 return getDerived().RebuildDependentScopeDeclRefExpr(
9907 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9908 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009909}
9910
9911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009913TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009914 // CXXConstructExprs other than for list-initialization and
9915 // CXXTemporaryObjectExpr are always implicit, so when we have
9916 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009917 if ((E->getNumArgs() == 1 ||
9918 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009919 (!getDerived().DropCallArgument(E->getArg(0))) &&
9920 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009921 return getDerived().TransformExpr(E->getArg(0));
9922
Douglas Gregora16548e2009-08-11 05:31:07 +00009923 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9924
9925 QualType T = getDerived().TransformType(E->getType());
9926 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009927 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009928
9929 CXXConstructorDecl *Constructor
9930 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009931 getDerived().TransformDecl(E->getLocStart(),
9932 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009933 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009935
Douglas Gregora16548e2009-08-11 05:31:07 +00009936 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009937 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009938 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009939 &ArgumentChanged))
9940 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009941
Douglas Gregora16548e2009-08-11 05:31:07 +00009942 if (!getDerived().AlwaysRebuild() &&
9943 T == E->getType() &&
9944 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009945 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009946 // Mark the constructor as referenced.
9947 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009948 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009949 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009950 }
Mike Stump11289f42009-09-09 15:08:12 +00009951
Douglas Gregordb121ba2009-12-14 16:27:04 +00009952 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +00009953 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00009954 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009955 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009956 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009957 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009958 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009959 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009960 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009961}
Mike Stump11289f42009-09-09 15:08:12 +00009962
Richard Smith5179eb72016-06-28 19:03:57 +00009963template<typename Derived>
9964ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
9965 CXXInheritedCtorInitExpr *E) {
9966 QualType T = getDerived().TransformType(E->getType());
9967 if (T.isNull())
9968 return ExprError();
9969
9970 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
9971 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
9972 if (!Constructor)
9973 return ExprError();
9974
9975 if (!getDerived().AlwaysRebuild() &&
9976 T == E->getType() &&
9977 Constructor == E->getConstructor()) {
9978 // Mark the constructor as referenced.
9979 // FIXME: Instantiation-specific
9980 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
9981 return E;
9982 }
9983
9984 return getDerived().RebuildCXXInheritedCtorInitExpr(
9985 T, E->getLocation(), Constructor,
9986 E->constructsVBase(), E->inheritedFromVBase());
9987}
9988
Douglas Gregora16548e2009-08-11 05:31:07 +00009989/// \brief Transform a C++ temporary-binding expression.
9990///
Douglas Gregor363b1512009-12-24 18:51:59 +00009991/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9992/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009994ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009995TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009996 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009997}
Mike Stump11289f42009-09-09 15:08:12 +00009998
John McCall5d413782010-12-06 08:20:24 +00009999/// \brief Transform a C++ expression that contains cleanups that should
10000/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010001///
John McCall5d413782010-12-06 08:20:24 +000010002/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010003/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010005ExprResult
John McCall5d413782010-12-06 08:20:24 +000010006TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010007 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010008}
Mike Stump11289f42009-09-09 15:08:12 +000010009
Douglas Gregora16548e2009-08-11 05:31:07 +000010010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010011ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010012TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010013 CXXTemporaryObjectExpr *E) {
10014 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10015 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010017
Douglas Gregora16548e2009-08-11 05:31:07 +000010018 CXXConstructorDecl *Constructor
10019 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010020 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010021 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010022 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010023 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010024
Douglas Gregora16548e2009-08-11 05:31:07 +000010025 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010026 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010027 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010028 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010029 &ArgumentChanged))
10030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010033 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010034 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010035 !ArgumentChanged) {
10036 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010037 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010038 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010039 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010040
Richard Smithd59b8322012-12-19 01:39:02 +000010041 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010042 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10043 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010044 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010045 E->getLocEnd());
10046}
Mike Stump11289f42009-09-09 15:08:12 +000010047
Douglas Gregora16548e2009-08-11 05:31:07 +000010048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010049ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010050TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010051 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010052 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010053 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010054 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10055 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010056 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010057 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010058 CEnd = E->capture_end();
10059 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010060 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010061 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010062 EnterExpressionEvaluationContext EEEC(getSema(),
10063 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010064 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10065 C->getCapturedVar()->getInit(),
10066 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010067
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010068 if (NewExprInitResult.isInvalid())
10069 return ExprError();
10070 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010071
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010072 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010073 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010074 getSema().buildLambdaInitCaptureInitialization(
10075 C->getLocation(), OldVD->getType()->isReferenceType(),
10076 OldVD->getIdentifier(),
10077 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010078 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010079 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10080 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010081 }
10082
Faisal Vali2cba1332013-10-23 06:44:28 +000010083 // Transform the template parameters, and add them to the current
10084 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010085 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010086 E->getTemplateParameterList());
10087
Richard Smith01014ce2014-11-20 23:53:14 +000010088 // Transform the type of the original lambda's call operator.
10089 // The transformation MUST be done in the CurrentInstantiationScope since
10090 // it introduces a mapping of the original to the newly created
10091 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010092 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010093 {
10094 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10095 FunctionProtoTypeLoc OldCallOpFPTL =
10096 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010097
10098 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010099 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010100 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010101 QualType NewCallOpType = TransformFunctionProtoType(
10102 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010103 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10104 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10105 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010106 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010107 if (NewCallOpType.isNull())
10108 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010109 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10110 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010111 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010112
Richard Smithc38498f2015-04-27 21:27:54 +000010113 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10114 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10115 LSI->GLTemplateParameterList = TPL;
10116
Eli Friedmand564afb2012-09-19 01:18:11 +000010117 // Create the local class that will describe the lambda.
10118 CXXRecordDecl *Class
10119 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010120 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010121 /*KnownDependent=*/false,
10122 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010123 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10124
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010125 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010126 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10127 Class, E->getIntroducerRange(), NewCallOpTSI,
10128 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010129 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10130 E->getCallOperator()->isConstexpr());
10131
Faisal Vali2cba1332013-10-23 06:44:28 +000010132 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010133
Faisal Vali2cba1332013-10-23 06:44:28 +000010134 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010135 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010136
Douglas Gregorb4328232012-02-14 00:00:48 +000010137 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010138 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010139 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010140
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010141 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010142 getSema().buildLambdaScope(LSI, NewCallOperator,
10143 E->getIntroducerRange(),
10144 E->getCaptureDefault(),
10145 E->getCaptureDefaultLoc(),
10146 E->hasExplicitParameters(),
10147 E->hasExplicitResultType(),
10148 E->isMutable());
10149
10150 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010151
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010152 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010153 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010154 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010155 CEnd = E->capture_end();
10156 C != CEnd; ++C) {
10157 // When we hit the first implicit capture, tell Sema that we've finished
10158 // the list of explicit captures.
10159 if (!FinishedExplicitCaptures && C->isImplicit()) {
10160 getSema().finishLambdaExplicitCaptures(LSI);
10161 FinishedExplicitCaptures = true;
10162 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010163
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010164 // Capturing 'this' is trivial.
10165 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010166 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10167 /*BuildAndDiagnose*/ true, nullptr,
10168 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010169 continue;
10170 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010171 // Captured expression will be recaptured during captured variables
10172 // rebuilding.
10173 if (C->capturesVLAType())
10174 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010175
Richard Smithba71c082013-05-16 06:20:58 +000010176 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010177 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010178 InitCaptureInfoTy InitExprTypePair =
10179 InitCaptureExprsAndTypes[C - E->capture_begin()];
10180 ExprResult Init = InitExprTypePair.first;
10181 QualType InitQualType = InitExprTypePair.second;
10182 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010183 Invalid = true;
10184 continue;
10185 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010186 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010187 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010188 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10189 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010190 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010191 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010192 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010193 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010194 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010195 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010196 continue;
10197 }
10198
10199 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10200
Douglas Gregor3e308b12012-02-14 19:27:52 +000010201 // Determine the capture kind for Sema.
10202 Sema::TryCaptureKind Kind
10203 = C->isImplicit()? Sema::TryCapture_Implicit
10204 : C->getCaptureKind() == LCK_ByCopy
10205 ? Sema::TryCapture_ExplicitByVal
10206 : Sema::TryCapture_ExplicitByRef;
10207 SourceLocation EllipsisLoc;
10208 if (C->isPackExpansion()) {
10209 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10210 bool ShouldExpand = false;
10211 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010212 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010213 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10214 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010215 Unexpanded,
10216 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010217 NumExpansions)) {
10218 Invalid = true;
10219 continue;
10220 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010221
Douglas Gregor3e308b12012-02-14 19:27:52 +000010222 if (ShouldExpand) {
10223 // The transform has determined that we should perform an expansion;
10224 // transform and capture each of the arguments.
10225 // expansion of the pattern. Do so.
10226 VarDecl *Pack = C->getCapturedVar();
10227 for (unsigned I = 0; I != *NumExpansions; ++I) {
10228 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10229 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010230 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010231 Pack));
10232 if (!CapturedVar) {
10233 Invalid = true;
10234 continue;
10235 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010236
Douglas Gregor3e308b12012-02-14 19:27:52 +000010237 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010238 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10239 }
Richard Smith9467be42014-06-06 17:33:35 +000010240
10241 // FIXME: Retain a pack expansion if RetainExpansion is true.
10242
Douglas Gregor3e308b12012-02-14 19:27:52 +000010243 continue;
10244 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010245
Douglas Gregor3e308b12012-02-14 19:27:52 +000010246 EllipsisLoc = C->getEllipsisLoc();
10247 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010248
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010249 // Transform the captured variable.
10250 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010251 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010252 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010253 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010254 Invalid = true;
10255 continue;
10256 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010257
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010258 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010259 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10260 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010261 }
10262 if (!FinishedExplicitCaptures)
10263 getSema().finishLambdaExplicitCaptures(LSI);
10264
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010265 // Enter a new evaluation context to insulate the lambda from any
10266 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010267 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010268
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010269 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010270 StmtResult Body =
10271 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10272
10273 // ActOnLambda* will pop the function scope for us.
10274 FuncScopeCleanup.disable();
10275
Douglas Gregorb4328232012-02-14 00:00:48 +000010276 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010277 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010278 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010279 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010280 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010281 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010282
Richard Smithc38498f2015-04-27 21:27:54 +000010283 // Copy the LSI before ActOnFinishFunctionBody removes it.
10284 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10285 // the call operator.
10286 auto LSICopy = *LSI;
10287 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10288 /*IsInstantiation*/ true);
10289 SavedContext.pop();
10290
10291 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10292 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010293}
10294
10295template<typename Derived>
10296ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010297TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010298 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010299 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10300 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010302
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010304 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010305 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010306 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010307 &ArgumentChanged))
10308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010309
Douglas Gregora16548e2009-08-11 05:31:07 +000010310 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010311 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010312 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010313 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010314
Douglas Gregora16548e2009-08-11 05:31:07 +000010315 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010316 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010317 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010318 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010319 E->getRParenLoc());
10320}
Mike Stump11289f42009-09-09 15:08:12 +000010321
Douglas Gregora16548e2009-08-11 05:31:07 +000010322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010323ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010324TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010325 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010326 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010327 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010328 Expr *OldBase;
10329 QualType BaseType;
10330 QualType ObjectType;
10331 if (!E->isImplicitAccess()) {
10332 OldBase = E->getBase();
10333 Base = getDerived().TransformExpr(OldBase);
10334 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010336
John McCall2d74de92009-12-01 22:10:20 +000010337 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010338 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010339 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010340 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010341 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010342 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010343 ObjectTy,
10344 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010345 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010346 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010347
John McCallba7bf592010-08-24 05:47:05 +000010348 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010349 BaseType = ((Expr*) Base.get())->getType();
10350 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010351 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010352 BaseType = getDerived().TransformType(E->getBaseType());
10353 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10354 }
Mike Stump11289f42009-09-09 15:08:12 +000010355
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010356 // Transform the first part of the nested-name-specifier that qualifies
10357 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010358 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010359 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010360 E->getFirstQualifierFoundInScope(),
10361 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010362
Douglas Gregore16af532011-02-28 18:50:33 +000010363 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010364 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010365 QualifierLoc
10366 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10367 ObjectType,
10368 FirstQualifierInScope);
10369 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010370 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010371 }
Mike Stump11289f42009-09-09 15:08:12 +000010372
Abramo Bagnara7945c982012-01-27 09:46:47 +000010373 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10374
John McCall31f82722010-11-12 08:19:04 +000010375 // TODO: If this is a conversion-function-id, verify that the
10376 // destination type name (if present) resolves the same way after
10377 // instantiation as it did in the local scope.
10378
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010379 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010380 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010381 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010383
John McCall2d74de92009-12-01 22:10:20 +000010384 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010385 // This is a reference to a member without an explicitly-specified
10386 // template argument list. Optimize for this common case.
10387 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010388 Base.get() == OldBase &&
10389 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010390 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010391 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010392 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010393 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010394
John McCallb268a282010-08-23 23:25:46 +000010395 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010396 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010397 E->isArrow(),
10398 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010399 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010400 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010401 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010402 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010403 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010404 }
10405
John McCall6b51f282009-11-23 01:53:49 +000010406 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010407 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10408 E->getNumTemplateArgs(),
10409 TransArgs))
10410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010411
John McCallb268a282010-08-23 23:25:46 +000010412 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010413 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010414 E->isArrow(),
10415 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010416 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010417 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010418 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010419 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010420 &TransArgs);
10421}
10422
10423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010425TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010426 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010427 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010428 QualType BaseType;
10429 if (!Old->isImplicitAccess()) {
10430 Base = getDerived().TransformExpr(Old->getBase());
10431 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010432 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010433 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010434 Old->isArrow());
10435 if (Base.isInvalid())
10436 return ExprError();
10437 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010438 } else {
10439 BaseType = getDerived().TransformType(Old->getBaseType());
10440 }
John McCall10eae182009-11-30 22:42:35 +000010441
Douglas Gregor0da1d432011-02-28 20:01:57 +000010442 NestedNameSpecifierLoc QualifierLoc;
10443 if (Old->getQualifierLoc()) {
10444 QualifierLoc
10445 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10446 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010447 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010448 }
10449
Abramo Bagnara7945c982012-01-27 09:46:47 +000010450 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10451
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010452 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010453 Sema::LookupOrdinaryName);
10454
10455 // Transform all the decls.
10456 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10457 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010458 NamedDecl *InstD = static_cast<NamedDecl*>(
10459 getDerived().TransformDecl(Old->getMemberLoc(),
10460 *I));
John McCall84d87672009-12-10 09:41:52 +000010461 if (!InstD) {
10462 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10463 // This can happen because of dependent hiding.
10464 if (isa<UsingShadowDecl>(*I))
10465 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010466 else {
10467 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010468 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010469 }
John McCall84d87672009-12-10 09:41:52 +000010470 }
John McCall10eae182009-11-30 22:42:35 +000010471
10472 // Expand using declarations.
10473 if (isa<UsingDecl>(InstD)) {
10474 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010475 for (auto *I : UD->shadows())
10476 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010477 continue;
10478 }
10479
10480 R.addDecl(InstD);
10481 }
10482
10483 R.resolveKind();
10484
Douglas Gregor9262f472010-04-27 18:19:34 +000010485 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010486 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010487 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010488 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010489 Old->getMemberLoc(),
10490 Old->getNamingClass()));
10491 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010492 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010493
Douglas Gregorda7be082010-04-27 16:10:10 +000010494 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010495 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010496
John McCall10eae182009-11-30 22:42:35 +000010497 TemplateArgumentListInfo TransArgs;
10498 if (Old->hasExplicitTemplateArgs()) {
10499 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10500 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010501 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10502 Old->getNumTemplateArgs(),
10503 TransArgs))
10504 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010505 }
John McCall38836f02010-01-15 08:34:02 +000010506
10507 // FIXME: to do this check properly, we will need to preserve the
10508 // first-qualifier-in-scope here, just in case we had a dependent
10509 // base (and therefore couldn't do the check) and a
10510 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010511 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010512
John McCallb268a282010-08-23 23:25:46 +000010513 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010514 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010515 Old->getOperatorLoc(),
10516 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010517 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010518 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010519 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010520 R,
10521 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010522 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010523}
10524
10525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010526ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010527TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010528 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010529 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10530 if (SubExpr.isInvalid())
10531 return ExprError();
10532
10533 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010534 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010535
10536 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10537}
10538
10539template<typename Derived>
10540ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010541TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010542 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10543 if (Pattern.isInvalid())
10544 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010545
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010546 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010547 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010548
Douglas Gregorb8840002011-01-14 21:20:45 +000010549 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10550 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010551}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010552
10553template<typename Derived>
10554ExprResult
10555TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10556 // If E is not value-dependent, then nothing will change when we transform it.
10557 // Note: This is an instantiation-centric view.
10558 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010559 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010560
Richard Smithd784e682015-09-23 21:41:42 +000010561 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010562
Richard Smithd784e682015-09-23 21:41:42 +000010563 ArrayRef<TemplateArgument> PackArgs;
10564 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010565
Richard Smithd784e682015-09-23 21:41:42 +000010566 // Find the argument list to transform.
10567 if (E->isPartiallySubstituted()) {
10568 PackArgs = E->getPartialArguments();
10569 } else if (E->isValueDependent()) {
10570 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10571 bool ShouldExpand = false;
10572 bool RetainExpansion = false;
10573 Optional<unsigned> NumExpansions;
10574 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10575 Unexpanded,
10576 ShouldExpand, RetainExpansion,
10577 NumExpansions))
10578 return ExprError();
10579
10580 // If we need to expand the pack, build a template argument from it and
10581 // expand that.
10582 if (ShouldExpand) {
10583 auto *Pack = E->getPack();
10584 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10585 ArgStorage = getSema().Context.getPackExpansionType(
10586 getSema().Context.getTypeDeclType(TTPD), None);
10587 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10588 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10589 } else {
10590 auto *VD = cast<ValueDecl>(Pack);
10591 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10592 VK_RValue, E->getPackLoc());
10593 if (DRE.isInvalid())
10594 return ExprError();
10595 ArgStorage = new (getSema().Context) PackExpansionExpr(
10596 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10597 }
10598 PackArgs = ArgStorage;
10599 }
10600 }
10601
10602 // If we're not expanding the pack, just transform the decl.
10603 if (!PackArgs.size()) {
10604 auto *Pack = cast_or_null<NamedDecl>(
10605 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010606 if (!Pack)
10607 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010608 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10609 E->getPackLoc(),
10610 E->getRParenLoc(), None, None);
10611 }
10612
10613 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10614 E->getPackLoc());
10615 {
10616 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10617 typedef TemplateArgumentLocInventIterator<
10618 Derived, const TemplateArgument*> PackLocIterator;
10619 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10620 PackLocIterator(*this, PackArgs.end()),
10621 TransformedPackArgs, /*Uneval*/true))
10622 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010623 }
10624
Richard Smithd784e682015-09-23 21:41:42 +000010625 SmallVector<TemplateArgument, 8> Args;
10626 bool PartialSubstitution = false;
10627 for (auto &Loc : TransformedPackArgs.arguments()) {
10628 Args.push_back(Loc.getArgument());
10629 if (Loc.getArgument().isPackExpansion())
10630 PartialSubstitution = true;
10631 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010632
Richard Smithd784e682015-09-23 21:41:42 +000010633 if (PartialSubstitution)
10634 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10635 E->getPackLoc(),
10636 E->getRParenLoc(), None, Args);
10637
10638 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010639 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010640 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010641}
10642
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010643template<typename Derived>
10644ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010645TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10646 SubstNonTypeTemplateParmPackExpr *E) {
10647 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010648 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010649}
10650
10651template<typename Derived>
10652ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010653TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10654 SubstNonTypeTemplateParmExpr *E) {
10655 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010656 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010657}
10658
10659template<typename Derived>
10660ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010661TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10662 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010663 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010664}
10665
10666template<typename Derived>
10667ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010668TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10669 MaterializeTemporaryExpr *E) {
10670 return getDerived().TransformExpr(E->GetTemporaryExpr());
10671}
Chad Rosier1dcde962012-08-08 18:46:20 +000010672
Douglas Gregorfe314812011-06-21 17:03:29 +000010673template<typename Derived>
10674ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010675TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10676 Expr *Pattern = E->getPattern();
10677
10678 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10679 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10680 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10681
10682 // Determine whether the set of unexpanded parameter packs can and should
10683 // be expanded.
10684 bool Expand = true;
10685 bool RetainExpansion = false;
10686 Optional<unsigned> NumExpansions;
10687 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10688 Pattern->getSourceRange(),
10689 Unexpanded,
10690 Expand, RetainExpansion,
10691 NumExpansions))
10692 return true;
10693
10694 if (!Expand) {
10695 // Do not expand any packs here, just transform and rebuild a fold
10696 // expression.
10697 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10698
10699 ExprResult LHS =
10700 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10701 if (LHS.isInvalid())
10702 return true;
10703
10704 ExprResult RHS =
10705 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10706 if (RHS.isInvalid())
10707 return true;
10708
10709 if (!getDerived().AlwaysRebuild() &&
10710 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10711 return E;
10712
10713 return getDerived().RebuildCXXFoldExpr(
10714 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10715 RHS.get(), E->getLocEnd());
10716 }
10717
10718 // The transform has determined that we should perform an elementwise
10719 // expansion of the pattern. Do so.
10720 ExprResult Result = getDerived().TransformExpr(E->getInit());
10721 if (Result.isInvalid())
10722 return true;
10723 bool LeftFold = E->isLeftFold();
10724
10725 // If we're retaining an expansion for a right fold, it is the innermost
10726 // component and takes the init (if any).
10727 if (!LeftFold && RetainExpansion) {
10728 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10729
10730 ExprResult Out = getDerived().TransformExpr(Pattern);
10731 if (Out.isInvalid())
10732 return true;
10733
10734 Result = getDerived().RebuildCXXFoldExpr(
10735 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10736 Result.get(), E->getLocEnd());
10737 if (Result.isInvalid())
10738 return true;
10739 }
10740
10741 for (unsigned I = 0; I != *NumExpansions; ++I) {
10742 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10743 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10744 ExprResult Out = getDerived().TransformExpr(Pattern);
10745 if (Out.isInvalid())
10746 return true;
10747
10748 if (Out.get()->containsUnexpandedParameterPack()) {
10749 // We still have a pack; retain a pack expansion for this slice.
10750 Result = getDerived().RebuildCXXFoldExpr(
10751 E->getLocStart(),
10752 LeftFold ? Result.get() : Out.get(),
10753 E->getOperator(), E->getEllipsisLoc(),
10754 LeftFold ? Out.get() : Result.get(),
10755 E->getLocEnd());
10756 } else if (Result.isUsable()) {
10757 // We've got down to a single element; build a binary operator.
10758 Result = getDerived().RebuildBinaryOperator(
10759 E->getEllipsisLoc(), E->getOperator(),
10760 LeftFold ? Result.get() : Out.get(),
10761 LeftFold ? Out.get() : Result.get());
10762 } else
10763 Result = Out;
10764
10765 if (Result.isInvalid())
10766 return true;
10767 }
10768
10769 // If we're retaining an expansion for a left fold, it is the outermost
10770 // component and takes the complete expansion so far as its init (if any).
10771 if (LeftFold && RetainExpansion) {
10772 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10773
10774 ExprResult Out = getDerived().TransformExpr(Pattern);
10775 if (Out.isInvalid())
10776 return true;
10777
10778 Result = getDerived().RebuildCXXFoldExpr(
10779 E->getLocStart(), Result.get(),
10780 E->getOperator(), E->getEllipsisLoc(),
10781 Out.get(), E->getLocEnd());
10782 if (Result.isInvalid())
10783 return true;
10784 }
10785
10786 // If we had no init and an empty pack, and we're not retaining an expansion,
10787 // then produce a fallback value or error.
10788 if (Result.isUnset())
10789 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10790 E->getOperator());
10791
10792 return Result;
10793}
10794
10795template<typename Derived>
10796ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010797TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10798 CXXStdInitializerListExpr *E) {
10799 return getDerived().TransformExpr(E->getSubExpr());
10800}
10801
10802template<typename Derived>
10803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010804TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010805 return SemaRef.MaybeBindToTemporary(E);
10806}
10807
10808template<typename Derived>
10809ExprResult
10810TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010811 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010812}
10813
10814template<typename Derived>
10815ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010816TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10817 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10818 if (SubExpr.isInvalid())
10819 return ExprError();
10820
10821 if (!getDerived().AlwaysRebuild() &&
10822 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010823 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010824
10825 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010826}
10827
10828template<typename Derived>
10829ExprResult
10830TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10831 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010832 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010833 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010834 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010835 /*IsCall=*/false, Elements, &ArgChanged))
10836 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010837
Ted Kremeneke65b0862012-03-06 20:05:56 +000010838 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10839 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010840
Ted Kremeneke65b0862012-03-06 20:05:56 +000010841 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10842 Elements.data(),
10843 Elements.size());
10844}
10845
10846template<typename Derived>
10847ExprResult
10848TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010849 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010850 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010851 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010852 bool ArgChanged = false;
10853 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10854 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010855
Ted Kremeneke65b0862012-03-06 20:05:56 +000010856 if (OrigElement.isPackExpansion()) {
10857 // This key/value element is a pack expansion.
10858 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10859 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10860 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10861 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10862
10863 // Determine whether the set of unexpanded parameter packs can
10864 // and should be expanded.
10865 bool Expand = true;
10866 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010867 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10868 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010869 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10870 OrigElement.Value->getLocEnd());
10871 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10872 PatternRange,
10873 Unexpanded,
10874 Expand, RetainExpansion,
10875 NumExpansions))
10876 return ExprError();
10877
10878 if (!Expand) {
10879 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010880 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010881 // expansion.
10882 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10883 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10884 if (Key.isInvalid())
10885 return ExprError();
10886
10887 if (Key.get() != OrigElement.Key)
10888 ArgChanged = true;
10889
10890 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10891 if (Value.isInvalid())
10892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010893
Ted Kremeneke65b0862012-03-06 20:05:56 +000010894 if (Value.get() != OrigElement.Value)
10895 ArgChanged = true;
10896
Chad Rosier1dcde962012-08-08 18:46:20 +000010897 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010898 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10899 };
10900 Elements.push_back(Expansion);
10901 continue;
10902 }
10903
10904 // Record right away that the argument was changed. This needs
10905 // to happen even if the array expands to nothing.
10906 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010907
Ted Kremeneke65b0862012-03-06 20:05:56 +000010908 // The transform has determined that we should perform an elementwise
10909 // expansion of the pattern. Do so.
10910 for (unsigned I = 0; I != *NumExpansions; ++I) {
10911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10912 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10913 if (Key.isInvalid())
10914 return ExprError();
10915
10916 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10917 if (Value.isInvalid())
10918 return ExprError();
10919
Chad Rosier1dcde962012-08-08 18:46:20 +000010920 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010921 Key.get(), Value.get(), SourceLocation(), NumExpansions
10922 };
10923
10924 // If any unexpanded parameter packs remain, we still have a
10925 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010926 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010927 if (Key.get()->containsUnexpandedParameterPack() ||
10928 Value.get()->containsUnexpandedParameterPack())
10929 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010930
Ted Kremeneke65b0862012-03-06 20:05:56 +000010931 Elements.push_back(Element);
10932 }
10933
Richard Smith9467be42014-06-06 17:33:35 +000010934 // FIXME: Retain a pack expansion if RetainExpansion is true.
10935
Ted Kremeneke65b0862012-03-06 20:05:56 +000010936 // We've finished with this pack expansion.
10937 continue;
10938 }
10939
10940 // Transform and check key.
10941 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10942 if (Key.isInvalid())
10943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010944
Ted Kremeneke65b0862012-03-06 20:05:56 +000010945 if (Key.get() != OrigElement.Key)
10946 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010947
Ted Kremeneke65b0862012-03-06 20:05:56 +000010948 // Transform and check value.
10949 ExprResult Value
10950 = getDerived().TransformExpr(OrigElement.Value);
10951 if (Value.isInvalid())
10952 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010953
Ted Kremeneke65b0862012-03-06 20:05:56 +000010954 if (Value.get() != OrigElement.Value)
10955 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010956
10957 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010958 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010959 };
10960 Elements.push_back(Element);
10961 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
Ted Kremeneke65b0862012-03-06 20:05:56 +000010963 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10964 return SemaRef.MaybeBindToTemporary(E);
10965
10966 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000010967 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000010968}
10969
Mike Stump11289f42009-09-09 15:08:12 +000010970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010972TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010973 TypeSourceInfo *EncodedTypeInfo
10974 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10975 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010977
Douglas Gregora16548e2009-08-11 05:31:07 +000010978 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010979 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010980 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010981
10982 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010983 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010984 E->getRParenLoc());
10985}
Mike Stump11289f42009-09-09 15:08:12 +000010986
Douglas Gregora16548e2009-08-11 05:31:07 +000010987template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010988ExprResult TreeTransform<Derived>::
10989TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010990 // This is a kind of implicit conversion, and it needs to get dropped
10991 // and recomputed for the same general reasons that ImplicitCastExprs
10992 // do, as well a more specific one: this expression is only valid when
10993 // it appears *immediately* as an argument expression.
10994 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010995}
10996
10997template<typename Derived>
10998ExprResult TreeTransform<Derived>::
10999TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011000 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011001 = getDerived().TransformType(E->getTypeInfoAsWritten());
11002 if (!TSInfo)
11003 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011004
John McCall31168b02011-06-15 23:02:42 +000011005 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011006 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011007 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011008
John McCall31168b02011-06-15 23:02:42 +000011009 if (!getDerived().AlwaysRebuild() &&
11010 TSInfo == E->getTypeInfoAsWritten() &&
11011 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011012 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011013
John McCall31168b02011-06-15 23:02:42 +000011014 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011015 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011016 Result.get());
11017}
11018
11019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011021TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011022 // Transform arguments.
11023 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011024 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011025 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011026 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011027 &ArgChanged))
11028 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011029
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011030 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11031 // Class message: transform the receiver type.
11032 TypeSourceInfo *ReceiverTypeInfo
11033 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11034 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011035 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011036
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011037 // If nothing changed, just retain the existing message send.
11038 if (!getDerived().AlwaysRebuild() &&
11039 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011040 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011041
11042 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011043 SmallVector<SourceLocation, 16> SelLocs;
11044 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011045 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11046 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011047 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011048 E->getMethodDecl(),
11049 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011050 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011051 E->getRightLoc());
11052 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011053 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11054 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11055 // Build a new class message send to 'super'.
11056 SmallVector<SourceLocation, 16> SelLocs;
11057 E->getSelectorLocs(SelLocs);
11058 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11059 E->getSelector(),
11060 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011061 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011062 E->getMethodDecl(),
11063 E->getLeftLoc(),
11064 Args,
11065 E->getRightLoc());
11066 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011067
11068 // Instance message: transform the receiver
11069 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11070 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011071 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011072 = getDerived().TransformExpr(E->getInstanceReceiver());
11073 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011074 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011075
11076 // If nothing changed, just retain the existing message send.
11077 if (!getDerived().AlwaysRebuild() &&
11078 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011079 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011080
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011081 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011082 SmallVector<SourceLocation, 16> SelLocs;
11083 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011084 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011085 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011086 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011087 E->getMethodDecl(),
11088 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011089 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011090 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011091}
11092
Mike Stump11289f42009-09-09 15:08:12 +000011093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011095TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011096 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011097}
11098
Mike Stump11289f42009-09-09 15:08:12 +000011099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011101TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011103}
11104
Mike Stump11289f42009-09-09 15:08:12 +000011105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011107TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011108 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011109 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011110 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011111 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011112
11113 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011114
Douglas Gregord51d90d2010-04-26 20:11:03 +000011115 // If nothing changed, just retain the existing expression.
11116 if (!getDerived().AlwaysRebuild() &&
11117 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011118 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011119
John McCallb268a282010-08-23 23:25:46 +000011120 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011121 E->getLocation(),
11122 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011123}
11124
Mike Stump11289f42009-09-09 15:08:12 +000011125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011127TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011128 // 'super' and types never change. Property never changes. Just
11129 // retain the existing expression.
11130 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011131 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011132
Douglas Gregor9faee212010-04-26 20:47:02 +000011133 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011134 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011135 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011136 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011137
Douglas Gregor9faee212010-04-26 20:47:02 +000011138 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011139
Douglas Gregor9faee212010-04-26 20:47:02 +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;
Douglas Gregora16548e2009-08-11 05:31:07 +000011144
John McCallb7bd14f2010-12-02 01:19:52 +000011145 if (E->isExplicitProperty())
11146 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11147 E->getExplicitProperty(),
11148 E->getLocation());
11149
11150 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011151 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011152 E->getImplicitPropertyGetter(),
11153 E->getImplicitPropertySetter(),
11154 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011155}
11156
Mike Stump11289f42009-09-09 15:08:12 +000011157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011158ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011159TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11160 // Transform the base expression.
11161 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11162 if (Base.isInvalid())
11163 return ExprError();
11164
11165 // Transform the key expression.
11166 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11167 if (Key.isInvalid())
11168 return ExprError();
11169
11170 // If nothing changed, just retain the existing expression.
11171 if (!getDerived().AlwaysRebuild() &&
11172 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011173 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011174
Chad Rosier1dcde962012-08-08 18:46:20 +000011175 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011176 Base.get(), Key.get(),
11177 E->getAtIndexMethodDecl(),
11178 E->setAtIndexMethodDecl());
11179}
11180
11181template<typename Derived>
11182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011183TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011184 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011185 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011186 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011187 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011188
Douglas Gregord51d90d2010-04-26 20:11:03 +000011189 // If nothing changed, just retain the existing expression.
11190 if (!getDerived().AlwaysRebuild() &&
11191 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011192 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011193
John McCallb268a282010-08-23 23:25:46 +000011194 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011195 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011196 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011197}
11198
Mike Stump11289f42009-09-09 15:08:12 +000011199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011200ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011201TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011202 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011203 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011204 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011205 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011206 SubExprs, &ArgumentChanged))
11207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011208
Douglas Gregora16548e2009-08-11 05:31:07 +000011209 if (!getDerived().AlwaysRebuild() &&
11210 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011211 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011212
Douglas Gregora16548e2009-08-11 05:31:07 +000011213 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011214 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011215 E->getRParenLoc());
11216}
11217
Mike Stump11289f42009-09-09 15:08:12 +000011218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011219ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011220TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11221 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11222 if (SrcExpr.isInvalid())
11223 return ExprError();
11224
11225 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11226 if (!Type)
11227 return ExprError();
11228
11229 if (!getDerived().AlwaysRebuild() &&
11230 Type == E->getTypeSourceInfo() &&
11231 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011232 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011233
11234 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11235 SrcExpr.get(), Type,
11236 E->getRParenLoc());
11237}
11238
11239template<typename Derived>
11240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011241TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011242 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011243
Craig Topperc3ec1492014-05-26 06:22:03 +000011244 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011245 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11246
11247 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011248 blockScope->TheDecl->setBlockMissingReturnType(
11249 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011250
Chris Lattner01cf8db2011-07-20 06:58:45 +000011251 SmallVector<ParmVarDecl*, 4> params;
11252 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011253
John McCallc8e321d2016-03-01 02:09:25 +000011254 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11255
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011256 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011257 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011258 if (getDerived().TransformFunctionTypeParams(
11259 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11260 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11261 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011262 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011263 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011264 }
John McCall490112f2011-02-04 18:33:18 +000011265
Eli Friedman34b49062012-01-26 03:00:14 +000011266 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011267 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011268
John McCallc8e321d2016-03-01 02:09:25 +000011269 auto epi = exprFunctionType->getExtProtoInfo();
11270 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11271
Jordan Rose5c382722013-03-08 21:51:21 +000011272 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011273 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011274 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011275
11276 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011277 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011278 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011279
11280 if (!oldBlock->blockMissingReturnType()) {
11281 blockScope->HasImplicitReturnType = false;
11282 blockScope->ReturnType = exprResultType;
11283 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011284
John McCall3882ace2011-01-05 12:14:39 +000011285 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011286 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011287 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011288 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011289 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011290 }
John McCall3882ace2011-01-05 12:14:39 +000011291
John McCall490112f2011-02-04 18:33:18 +000011292#ifndef NDEBUG
11293 // In builds with assertions, make sure that we captured everything we
11294 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011295 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011296 for (const auto &I : oldBlock->captures()) {
11297 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011298
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011299 // Ignore parameter packs.
11300 if (isa<ParmVarDecl>(oldCapture) &&
11301 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11302 continue;
John McCall490112f2011-02-04 18:33:18 +000011303
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011304 VarDecl *newCapture =
11305 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11306 oldCapture));
11307 assert(blockScope->CaptureMap.count(newCapture));
11308 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011309 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011310 }
11311#endif
11312
11313 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011314 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011315}
11316
Mike Stump11289f42009-09-09 15:08:12 +000011317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011318ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011319TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011320 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011321}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011322
11323template<typename Derived>
11324ExprResult
11325TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011326 QualType RetTy = getDerived().TransformType(E->getType());
11327 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011328 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011329 SubExprs.reserve(E->getNumSubExprs());
11330 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11331 SubExprs, &ArgumentChanged))
11332 return ExprError();
11333
11334 if (!getDerived().AlwaysRebuild() &&
11335 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011336 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011337
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011338 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011339 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011340}
Chad Rosier1dcde962012-08-08 18:46:20 +000011341
Douglas Gregora16548e2009-08-11 05:31:07 +000011342//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011343// Type reconstruction
11344//===----------------------------------------------------------------------===//
11345
Mike Stump11289f42009-09-09 15:08:12 +000011346template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011347QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11348 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011349 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011350 getDerived().getBaseEntity());
11351}
11352
Mike Stump11289f42009-09-09 15:08:12 +000011353template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011354QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11355 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011356 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011357 getDerived().getBaseEntity());
11358}
11359
Mike Stump11289f42009-09-09 15:08:12 +000011360template<typename Derived>
11361QualType
John McCall70dd5f62009-10-30 00:06:24 +000011362TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11363 bool WrittenAsLValue,
11364 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011365 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011366 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011367}
11368
11369template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011370QualType
John McCall70dd5f62009-10-30 00:06:24 +000011371TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11372 QualType ClassType,
11373 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011374 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11375 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011376}
11377
11378template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011379QualType TreeTransform<Derived>::RebuildObjCObjectType(
11380 QualType BaseType,
11381 SourceLocation Loc,
11382 SourceLocation TypeArgsLAngleLoc,
11383 ArrayRef<TypeSourceInfo *> TypeArgs,
11384 SourceLocation TypeArgsRAngleLoc,
11385 SourceLocation ProtocolLAngleLoc,
11386 ArrayRef<ObjCProtocolDecl *> Protocols,
11387 ArrayRef<SourceLocation> ProtocolLocs,
11388 SourceLocation ProtocolRAngleLoc) {
11389 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11390 TypeArgs, TypeArgsRAngleLoc,
11391 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11392 ProtocolRAngleLoc,
11393 /*FailOnError=*/true);
11394}
11395
11396template<typename Derived>
11397QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11398 QualType PointeeType,
11399 SourceLocation Star) {
11400 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11401}
11402
11403template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011404QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011405TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11406 ArrayType::ArraySizeModifier SizeMod,
11407 const llvm::APInt *Size,
11408 Expr *SizeExpr,
11409 unsigned IndexTypeQuals,
11410 SourceRange BracketsRange) {
11411 if (SizeExpr || !Size)
11412 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11413 IndexTypeQuals, BracketsRange,
11414 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011415
11416 QualType Types[] = {
11417 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11418 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11419 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011420 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011421 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011422 QualType SizeType;
11423 for (unsigned I = 0; I != NumTypes; ++I)
11424 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11425 SizeType = Types[I];
11426 break;
11427 }
Mike Stump11289f42009-09-09 15:08:12 +000011428
Eli Friedman9562f392012-01-25 23:20:27 +000011429 // Note that we can return a VariableArrayType here in the case where
11430 // the element type was a dependent VariableArrayType.
11431 IntegerLiteral *ArraySize
11432 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11433 /*FIXME*/BracketsRange.getBegin());
11434 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011435 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011436 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011437}
Mike Stump11289f42009-09-09 15:08:12 +000011438
Douglas Gregord6ff3322009-08-04 16:50:30 +000011439template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011440QualType
11441TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011442 ArrayType::ArraySizeModifier SizeMod,
11443 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011444 unsigned IndexTypeQuals,
11445 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011446 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011447 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011448}
11449
11450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011451QualType
Mike Stump11289f42009-09-09 15:08:12 +000011452TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011453 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011454 unsigned IndexTypeQuals,
11455 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011456 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011457 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011458}
Mike Stump11289f42009-09-09 15:08:12 +000011459
Douglas Gregord6ff3322009-08-04 16:50:30 +000011460template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011461QualType
11462TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011463 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011464 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011465 unsigned IndexTypeQuals,
11466 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011467 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011468 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011469 IndexTypeQuals, BracketsRange);
11470}
11471
11472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011473QualType
11474TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011475 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011476 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011477 unsigned IndexTypeQuals,
11478 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011479 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011480 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011481 IndexTypeQuals, BracketsRange);
11482}
11483
11484template<typename Derived>
11485QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011486 unsigned NumElements,
11487 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011488 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011489 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011490}
Mike Stump11289f42009-09-09 15:08:12 +000011491
Douglas Gregord6ff3322009-08-04 16:50:30 +000011492template<typename Derived>
11493QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11494 unsigned NumElements,
11495 SourceLocation AttributeLoc) {
11496 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11497 NumElements, true);
11498 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011499 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11500 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011501 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011502}
Mike Stump11289f42009-09-09 15:08:12 +000011503
Douglas Gregord6ff3322009-08-04 16:50:30 +000011504template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011505QualType
11506TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011507 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011508 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011509 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011510}
Mike Stump11289f42009-09-09 15:08:12 +000011511
Douglas Gregord6ff3322009-08-04 16:50:30 +000011512template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011513QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11514 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011515 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011516 const FunctionProtoType::ExtProtoInfo &EPI) {
11517 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011518 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011519 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011520 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011521}
Mike Stump11289f42009-09-09 15:08:12 +000011522
Douglas Gregord6ff3322009-08-04 16:50:30 +000011523template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011524QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11525 return SemaRef.Context.getFunctionNoProtoType(T);
11526}
11527
11528template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011529QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11530 assert(D && "no decl found");
11531 if (D->isInvalidDecl()) return QualType();
11532
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011533 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011534 TypeDecl *Ty;
11535 if (isa<UsingDecl>(D)) {
11536 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011537 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011538 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11539
11540 // A valid resolved using typename decl points to exactly one type decl.
11541 assert(++Using->shadow_begin() == Using->shadow_end());
11542 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011543
John McCallb96ec562009-12-04 22:46:56 +000011544 } else {
11545 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11546 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11547 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11548 }
11549
11550 return SemaRef.Context.getTypeDeclType(Ty);
11551}
11552
11553template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011554QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11555 SourceLocation Loc) {
11556 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011557}
11558
11559template<typename Derived>
11560QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11561 return SemaRef.Context.getTypeOfType(Underlying);
11562}
11563
11564template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011565QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11566 SourceLocation Loc) {
11567 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011568}
11569
11570template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011571QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11572 UnaryTransformType::UTTKind UKind,
11573 SourceLocation Loc) {
11574 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11575}
11576
11577template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011578QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011579 TemplateName Template,
11580 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011581 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011582 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011583}
Mike Stump11289f42009-09-09 15:08:12 +000011584
Douglas Gregor1135c352009-08-06 05:28:30 +000011585template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011586QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11587 SourceLocation KWLoc) {
11588 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11589}
11590
11591template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011592QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11593 SourceLocation KWLoc) {
11594 return SemaRef.BuildPipeType(ValueType, KWLoc);
11595}
11596
11597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011598TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011599TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011600 bool TemplateKW,
11601 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011602 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011603 Template);
11604}
11605
11606template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011607TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011608TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11609 const IdentifierInfo &Name,
11610 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011611 QualType ObjectType,
11612 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011613 UnqualifiedId TemplateName;
11614 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011615 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011616 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011617 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011618 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011619 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011620 /*EnteringContext=*/false,
11621 Template);
John McCall31f82722010-11-12 08:19:04 +000011622 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011623}
Mike Stump11289f42009-09-09 15:08:12 +000011624
Douglas Gregora16548e2009-08-11 05:31:07 +000011625template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011626TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011627TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011628 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011629 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011630 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011631 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011632 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011633 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011634 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011635 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011636 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011637 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011638 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011639 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011640 /*EnteringContext=*/false,
11641 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011642 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011643}
Chad Rosier1dcde962012-08-08 18:46:20 +000011644
Douglas Gregor71395fa2009-11-04 00:56:37 +000011645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011646ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011647TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11648 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011649 Expr *OrigCallee,
11650 Expr *First,
11651 Expr *Second) {
11652 Expr *Callee = OrigCallee->IgnoreParenCasts();
11653 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011654
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011655 if (First->getObjectKind() == OK_ObjCProperty) {
11656 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11657 if (BinaryOperator::isAssignmentOp(Opc))
11658 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11659 First, Second);
11660 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11661 if (Result.isInvalid())
11662 return ExprError();
11663 First = Result.get();
11664 }
11665
11666 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11667 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11668 if (Result.isInvalid())
11669 return ExprError();
11670 Second = Result.get();
11671 }
11672
Douglas Gregora16548e2009-08-11 05:31:07 +000011673 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011674 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011675 if (!First->getType()->isOverloadableType() &&
11676 !Second->getType()->isOverloadableType())
11677 return getSema().CreateBuiltinArraySubscriptExpr(First,
11678 Callee->getLocStart(),
11679 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011680 } else if (Op == OO_Arrow) {
11681 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011682 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11683 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011684 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011685 // The argument is not of overloadable type, so try to create a
11686 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011687 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011688 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011689
John McCallb268a282010-08-23 23:25:46 +000011690 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011691 }
11692 } else {
John McCallb268a282010-08-23 23:25:46 +000011693 if (!First->getType()->isOverloadableType() &&
11694 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011695 // Neither of the arguments is an overloadable type, so try to
11696 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011697 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011698 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011699 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011700 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011702
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011703 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011704 }
11705 }
Mike Stump11289f42009-09-09 15:08:12 +000011706
11707 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011708 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011709 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011710
John McCallb268a282010-08-23 23:25:46 +000011711 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011712 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011713 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011714 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011715 // If we've resolved this to a particular non-member function, just call
11716 // that function. If we resolved it to a member function,
11717 // CreateOverloaded* will find that function for us.
11718 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11719 if (!isa<CXXMethodDecl>(ND))
11720 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011721 }
Mike Stump11289f42009-09-09 15:08:12 +000011722
Douglas Gregora16548e2009-08-11 05:31:07 +000011723 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011724 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011725 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011726
Douglas Gregora16548e2009-08-11 05:31:07 +000011727 // Create the overloaded operator invocation for unary operators.
11728 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011729 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011730 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011731 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011732 }
Mike Stump11289f42009-09-09 15:08:12 +000011733
Douglas Gregore9d62932011-07-15 16:25:15 +000011734 if (Op == OO_Subscript) {
11735 SourceLocation LBrace;
11736 SourceLocation RBrace;
11737
11738 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011739 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011740 LBrace = SourceLocation::getFromRawEncoding(
11741 NameLoc.CXXOperatorName.BeginOpNameLoc);
11742 RBrace = SourceLocation::getFromRawEncoding(
11743 NameLoc.CXXOperatorName.EndOpNameLoc);
11744 } else {
11745 LBrace = Callee->getLocStart();
11746 RBrace = OpLoc;
11747 }
11748
11749 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11750 First, Second);
11751 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011752
Douglas Gregora16548e2009-08-11 05:31:07 +000011753 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011754 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011755 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011756 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11757 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011759
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011760 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011761}
Mike Stump11289f42009-09-09 15:08:12 +000011762
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011763template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011764ExprResult
John McCallb268a282010-08-23 23:25:46 +000011765TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011766 SourceLocation OperatorLoc,
11767 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011768 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011769 TypeSourceInfo *ScopeType,
11770 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011771 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011772 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011773 QualType BaseType = Base->getType();
11774 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011775 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011776 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011777 !BaseType->getAs<PointerType>()->getPointeeType()
11778 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011779 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011780 return SemaRef.BuildPseudoDestructorExpr(
11781 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11782 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011783 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011784
Douglas Gregor678f90d2010-02-25 01:56:36 +000011785 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011786 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11787 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11788 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11789 NameInfo.setNamedTypeInfo(DestroyedType);
11790
Richard Smith8e4a3862012-05-15 06:15:11 +000011791 // The scope type is now known to be a valid nested name specifier
11792 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011793 if (ScopeType) {
11794 if (!ScopeType->getType()->getAs<TagType>()) {
11795 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11796 diag::err_expected_class_or_namespace)
11797 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11798 return ExprError();
11799 }
11800 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11801 CCLoc);
11802 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011803
Abramo Bagnara7945c982012-01-27 09:46:47 +000011804 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011805 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011806 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011807 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011808 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011809 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011810 /*TemplateArgs*/ nullptr,
11811 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011812}
11813
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011814template<typename Derived>
11815StmtResult
11816TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011817 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011818 CapturedDecl *CD = S->getCapturedDecl();
11819 unsigned NumParams = CD->getNumParams();
11820 unsigned ContextParamPos = CD->getContextParamPosition();
11821 SmallVector<Sema::CapturedParamNameType, 4> Params;
11822 for (unsigned I = 0; I < NumParams; ++I) {
11823 if (I != ContextParamPos) {
11824 Params.push_back(
11825 std::make_pair(
11826 CD->getParam(I)->getName(),
11827 getDerived().TransformType(CD->getParam(I)->getType())));
11828 } else {
11829 Params.push_back(std::make_pair(StringRef(), QualType()));
11830 }
11831 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011832 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011833 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011834 StmtResult Body;
11835 {
11836 Sema::CompoundScopeRAII CompoundScope(getSema());
11837 Body = getDerived().TransformStmt(S->getCapturedStmt());
11838 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011839
11840 if (Body.isInvalid()) {
11841 getSema().ActOnCapturedRegionError();
11842 return StmtError();
11843 }
11844
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011845 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011846}
11847
Douglas Gregord6ff3322009-08-04 16:50:30 +000011848} // end namespace clang
11849
Hans Wennborg59dbe862015-09-29 20:56:43 +000011850#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H