blob: 0dbdebf5db6170599b6698143136f44f62776b50 [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,
Richard Smitha547eb22016-07-14 00:11:03 +00001177 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001178 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001180 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.
Richard Smitha547eb22016-07-14 00:11:03 +00001187 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001188 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001189 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, 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
Carlo Bertolli2404b172016-07-13 15:37:16 +00001784 /// Build a new OpenMP 'use_device_ptr' clause.
1785 ///
1786 /// By default, performs semantic analysis to build the new OpenMP clause.
1787 /// Subclasses may override this routine to provide different behavior.
1788 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1789 SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1793 EndLoc);
1794 }
1795
Carlo Bertolli70594e92016-07-13 17:16:49 +00001796 /// Build a new OpenMP 'is_device_ptr' clause.
1797 ///
1798 /// By default, performs semantic analysis to build the new OpenMP clause.
1799 /// Subclasses may override this routine to provide different behavior.
1800 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1801 SourceLocation StartLoc,
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1805 EndLoc);
1806 }
1807
James Dennett2a4d13c2012-06-15 07:13:21 +00001808 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001809 ///
1810 /// By default, performs semantic analysis to build the new statement.
1811 /// Subclasses may override this routine to provide different behavior.
1812 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1813 Expr *object) {
1814 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1815 }
1816
James Dennett2a4d13c2012-06-15 07:13:21 +00001817 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001818 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001819 /// By default, performs semantic analysis to build the new statement.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001822 Expr *Object, Stmt *Body) {
1823 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001824 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001825
James Dennett2a4d13c2012-06-15 07:13:21 +00001826 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001827 ///
1828 /// By default, performs semantic analysis to build the new statement.
1829 /// Subclasses may override this routine to provide different behavior.
1830 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1831 Stmt *Body) {
1832 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1833 }
John McCall53848232011-07-27 01:07:15 +00001834
Douglas Gregorf68a5082010-04-22 23:10:45 +00001835 /// \brief Build a new Objective-C fast enumeration statement.
1836 ///
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001840 Stmt *Element,
1841 Expr *Collection,
1842 SourceLocation RParenLoc,
1843 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001844 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001845 Element,
John McCallb268a282010-08-23 23:25:46 +00001846 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001847 RParenLoc);
1848 if (ForEachStmt.isInvalid())
1849 return StmtError();
1850
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001851 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001853
Douglas Gregorebe10102009-08-20 07:17:43 +00001854 /// \brief Build a new C++ exception declaration.
1855 ///
1856 /// By default, performs semantic analysis to build the new decaration.
1857 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001858 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001859 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001860 SourceLocation StartLoc,
1861 SourceLocation IdLoc,
1862 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001863 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001864 StartLoc, IdLoc, Id);
1865 if (Var)
1866 getSema().CurContext->addDecl(Var);
1867 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001868 }
1869
1870 /// \brief Build a new C++ catch statement.
1871 ///
1872 /// By default, performs semantic analysis to build the new statement.
1873 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001874 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001875 VarDecl *ExceptionDecl,
1876 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001877 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1878 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001879 }
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregorebe10102009-08-20 07:17:43 +00001881 /// \brief Build a new C++ try statement.
1882 ///
1883 /// By default, performs semantic analysis to build the new statement.
1884 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001885 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1886 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001887 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001888 }
Mike Stump11289f42009-09-09 15:08:12 +00001889
Richard Smith02e85f32011-04-14 22:09:26 +00001890 /// \brief Build a new C++0x range-based for statement.
1891 ///
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
1894 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001895 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001896 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001897 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001898 Expr *Cond, Expr *Inc,
1899 Stmt *LoopVar,
1900 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001901 // If we've just learned that the range is actually an Objective-C
1902 // collection, treat this as an Objective-C fast enumeration loop.
1903 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1904 if (RangeStmt->isSingleDecl()) {
1905 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001906 if (RangeVar->isInvalidDecl())
1907 return StmtError();
1908
Douglas Gregorf7106af2013-04-08 18:40:13 +00001909 Expr *RangeExpr = RangeVar->getInit();
1910 if (!RangeExpr->isTypeDependent() &&
1911 RangeExpr->getType()->isObjCObjectPointerType())
1912 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1913 RParenLoc);
1914 }
1915 }
1916 }
1917
Richard Smithcfd53b42015-10-22 06:13:50 +00001918 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001919 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001920 Cond, Inc, LoopVar, RParenLoc,
1921 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001922 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001923
1924 /// \brief Build a new C++0x range-based for statement.
1925 ///
1926 /// By default, performs semantic analysis to build the new statement.
1927 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001928 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001929 bool IsIfExists,
1930 NestedNameSpecifierLoc QualifierLoc,
1931 DeclarationNameInfo NameInfo,
1932 Stmt *Nested) {
1933 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1934 QualifierLoc, NameInfo, Nested);
1935 }
1936
Richard Smith02e85f32011-04-14 22:09:26 +00001937 /// \brief Attach body to a C++0x range-based for statement.
1938 ///
1939 /// By default, performs semantic analysis to finish the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
1941 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1942 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1943 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001944
David Majnemerfad8f482013-10-15 09:33:02 +00001945 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001946 Stmt *TryBlock, Stmt *Handler) {
1947 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001948 }
1949
David Majnemerfad8f482013-10-15 09:33:02 +00001950 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001951 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001952 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001953 }
1954
David Majnemerfad8f482013-10-15 09:33:02 +00001955 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001956 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001957 }
1958
Alexey Bataevec474782014-10-09 08:45:04 +00001959 /// \brief Build a new predefined expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
1963 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1964 PredefinedExpr::IdentType IT) {
1965 return getSema().BuildPredefinedExpr(Loc, IT);
1966 }
1967
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// \brief Build a new expression that references a declaration.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001973 LookupResult &R,
1974 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001975 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1976 }
1977
1978
1979 /// \brief Build a new expression that references a declaration.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001983 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001984 ValueDecl *VD,
1985 const DeclarationNameInfo &NameInfo,
1986 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001987 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001988 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001989
1990 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001991
1992 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001996 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002001 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 }
2003
Douglas Gregorad8a3362009-09-04 17:36:40 +00002004 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002005 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002009 SourceLocation OperatorLoc,
2010 bool isArrow,
2011 CXXScopeSpec &SS,
2012 TypeSourceInfo *ScopeType,
2013 SourceLocation CCLoc,
2014 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002015 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002022 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002023 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002024 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregor882211c2010-04-28 22:16:22 +00002027 /// \brief Build a new builtin offsetof expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002031 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002032 TypeSourceInfo *Type,
2033 ArrayRef<Sema::OffsetOfComponent> Components,
2034 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002035 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002036 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002038
2039 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002040 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002044 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2045 SourceLocation OpLoc,
2046 UnaryExprOrTypeTrait ExprKind,
2047 SourceRange R) {
2048 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 }
2050
Peter Collingbournee190dee2011-03-11 19:24:49 +00002051 /// \brief Build a new sizeof, alignof or vec step expression with an
2052 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002056 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2057 UnaryExprOrTypeTrait ExprKind,
2058 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002059 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002060 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002062 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002063
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002064 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 }
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002073 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002075 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002076 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 RBracketLoc);
2078 }
2079
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002080 /// \brief Build a new array section expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
2084 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2085 Expr *LowerBound,
2086 SourceLocation ColonLoc, Expr *Length,
2087 SourceLocation RBracketLoc) {
2088 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2089 ColonLoc, Length, RBracketLoc);
2090 }
2091
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002093 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002096 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002098 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002099 Expr *ExecConfig = nullptr) {
2100 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002101 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 }
2103
2104 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002105 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002108 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002109 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002110 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002111 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002112 const DeclarationNameInfo &MemberNameInfo,
2113 ValueDecl *Member,
2114 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002115 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002116 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002117 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2118 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002119 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002120 // We have a reference to an unnamed field. This is always the
2121 // base of an anonymous struct/union member access, i.e. the
2122 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002123 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002124 assert(Member->getType()->isRecordType() &&
2125 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002126
Richard Smithcab9a7d2011-10-26 19:06:56 +00002127 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002128 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002129 QualifierLoc.getNestedNameSpecifier(),
2130 FoundDecl, Member);
2131 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002132 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002133 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002134 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002135 MemberExpr *ME = new (getSema().Context)
2136 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2137 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002138 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002141 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002142 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002143
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002144 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002145 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002146
John McCall16df1e52010-03-30 21:47:33 +00002147 // FIXME: this involves duplicating earlier analysis in a lot of
2148 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002149 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002150 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002151 R.resolveKind();
2152
John McCallb268a282010-08-23 23:25:46 +00002153 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002154 SS, TemplateKWLoc,
2155 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002156 R, ExplicitTemplateArgs,
2157 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 }
Mike Stump11289f42009-09-09 15:08:12 +00002159
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002161 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002164 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002165 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002166 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002167 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 }
2169
2170 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002171 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002175 SourceLocation QuestionLoc,
2176 Expr *LHS,
2177 SourceLocation ColonLoc,
2178 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002179 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2180 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
2182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002188 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002190 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002191 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002192 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 }
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002196 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002200 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002202 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002203 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002204 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 }
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 SourceLocation OpLoc,
2213 SourceLocation AccessorLoc,
2214 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002215
John McCall10eae182009-11-30 22:42:35 +00002216 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002217 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002218 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002219 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002220 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002221 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002222 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002223 /* TemplateArgs */ nullptr,
2224 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 }
Mike Stump11289f42009-09-09 15:08:12 +00002226
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002228 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002232 MultiExprArg Inits,
2233 SourceLocation RBraceLoc,
2234 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002235 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002236 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002237 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002238 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002239
Douglas Gregord3d93062009-11-09 17:16:50 +00002240 // Patch in the result type we were given, which may have been computed
2241 // when the initial InitListExpr was built.
2242 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2243 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002244 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002248 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002251 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 MultiExprArg ArrayExprs,
2253 SourceLocation EqualOrColonLoc,
2254 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002255 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002256 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002258 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002261
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002262 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 }
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002266 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 /// By default, builds the implicit value initialization without performing
2268 /// any semantic analysis. Subclasses may override this routine to provide
2269 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002271 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 }
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002275 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002278 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002279 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002280 SourceLocation RParenLoc) {
2281 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002282 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002283 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
2285
2286 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002287 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002290 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002291 MultiExprArg SubExprs,
2292 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002293 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 }
Mike Stump11289f42009-09-09 15:08:12 +00002295
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002297 ///
2298 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// rather than attempting to map the label statement itself.
2300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002301 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002302 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002303 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 }
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002307 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002310 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002311 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002313 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 /// \brief Build a new __builtin_choose_expr expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002320 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002321 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 SourceLocation RParenLoc) {
2323 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002324 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 RParenLoc);
2326 }
Mike Stump11289f42009-09-09 15:08:12 +00002327
Peter Collingbourne91147592011-04-15 00:35:48 +00002328 /// \brief Build a new generic selection expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
2332 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2333 SourceLocation DefaultLoc,
2334 SourceLocation RParenLoc,
2335 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002336 ArrayRef<TypeSourceInfo *> Types,
2337 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002338 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002339 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002340 }
2341
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 /// \brief Build a new overloaded operator call expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// The semantic analysis provides the behavior of template instantiation,
2346 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002347 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 /// argument-dependent lookup, etc. Subclasses may override this routine to
2349 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *Callee,
2353 Expr *First,
2354 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002355
2356 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 /// reinterpret_cast.
2358 ///
2359 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002360 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002362 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 Stmt::StmtClass Class,
2364 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002365 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 SourceLocation RAngleLoc,
2367 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002368 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 SourceLocation RParenLoc) {
2370 switch (Class) {
2371 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002372 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002373 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002374 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002375
2376 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002377 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002378 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002379 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002380
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002382 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002383 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002384 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002388 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002389 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002390 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002393 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 }
Mike Stump11289f42009-09-09 15:08:12 +00002396
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 /// \brief Build a new C++ static_cast expression.
2398 ///
2399 /// By default, performs semantic analysis to build the new expression.
2400 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002401 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002403 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 SourceLocation RAngleLoc,
2405 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002406 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002408 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002409 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002410 SourceRange(LAngleLoc, RAngleLoc),
2411 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 }
2413
2414 /// \brief Build a new C++ dynamic_cast expression.
2415 ///
2416 /// By default, performs semantic analysis to build the new expression.
2417 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002418 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002420 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 SourceLocation RAngleLoc,
2422 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002423 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002425 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002426 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002427 SourceRange(LAngleLoc, RAngleLoc),
2428 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 }
2430
2431 /// \brief Build a new C++ reinterpret_cast expression.
2432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002435 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002437 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 SourceLocation RAngleLoc,
2439 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002440 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002442 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002443 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002444 SourceRange(LAngleLoc, RAngleLoc),
2445 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
2448 /// \brief Build a new C++ const_cast expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002452 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002454 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002455 SourceLocation RAngleLoc,
2456 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002457 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002459 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002460 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002461 SourceRange(LAngleLoc, RAngleLoc),
2462 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
Mike Stump11289f42009-09-09 15:08:12 +00002464
Douglas Gregora16548e2009-08-11 05:31:07 +00002465 /// \brief Build a new C++ functional-style cast expression.
2466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002469 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2470 SourceLocation LParenLoc,
2471 Expr *Sub,
2472 SourceLocation RParenLoc) {
2473 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002474 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 RParenLoc);
2476 }
Mike Stump11289f42009-09-09 15:08:12 +00002477
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 /// \brief Build a new C++ typeid(type) expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002482 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002483 SourceLocation TypeidLoc,
2484 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002486 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002487 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
Mike Stump11289f42009-09-09 15:08:12 +00002489
Francois Pichet9f4f2072010-09-08 12:20:18 +00002490
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 /// \brief Build a new C++ typeid(expr) expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002495 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002496 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002497 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002499 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002500 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002501 }
2502
Francois Pichet9f4f2072010-09-08 12:20:18 +00002503 /// \brief Build a new C++ __uuidof(type) expression.
2504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
2507 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2508 SourceLocation TypeidLoc,
2509 TypeSourceInfo *Operand,
2510 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002511 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002512 RParenLoc);
2513 }
2514
2515 /// \brief Build a new C++ __uuidof(expr) expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
2519 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2520 SourceLocation TypeidLoc,
2521 Expr *Operand,
2522 SourceLocation RParenLoc) {
2523 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2524 RParenLoc);
2525 }
2526
Douglas Gregora16548e2009-08-11 05:31:07 +00002527 /// \brief Build a new C++ "this" expression.
2528 ///
2529 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002530 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002532 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002533 QualType ThisType,
2534 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002535 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002536 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 }
2538
2539 /// \brief Build a new C++ throw expression.
2540 ///
2541 /// By default, performs semantic analysis to build the new expression.
2542 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002543 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2544 bool IsThrownVariableInScope) {
2545 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 }
2547
2548 /// \brief Build a new C++ default-argument expression.
2549 ///
2550 /// By default, builds a new default-argument expression, which does not
2551 /// require any semantic analysis. Subclasses may override this routine to
2552 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002553 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002554 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002555 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 }
2557
Richard Smith852c9db2013-04-20 22:23:05 +00002558 /// \brief Build a new C++11 default-initialization expression.
2559 ///
2560 /// By default, builds a new default field initialization expression, which
2561 /// does not require any semantic analysis. Subclasses may override this
2562 /// routine to provide different behavior.
2563 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2564 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002565 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002566 }
2567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 /// \brief Build a new C++ zero-initialization expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002572 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2573 SourceLocation LParenLoc,
2574 SourceLocation RParenLoc) {
2575 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002576 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002577 }
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 /// \brief Build a new C++ "new" expression.
2580 ///
2581 /// By default, performs semantic analysis to build the new expression.
2582 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002583 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002584 bool UseGlobal,
2585 SourceLocation PlacementLParen,
2586 MultiExprArg PlacementArgs,
2587 SourceLocation PlacementRParen,
2588 SourceRange TypeIdParens,
2589 QualType AllocatedType,
2590 TypeSourceInfo *AllocatedTypeInfo,
2591 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002592 SourceRange DirectInitRange,
2593 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002594 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002596 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002597 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002598 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002599 AllocatedType,
2600 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002601 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002602 DirectInitRange,
2603 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 }
Mike Stump11289f42009-09-09 15:08:12 +00002605
Douglas Gregora16548e2009-08-11 05:31:07 +00002606 /// \brief Build a new C++ "delete" expression.
2607 ///
2608 /// By default, performs semantic analysis to build the new expression.
2609 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002610 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002611 bool IsGlobalDelete,
2612 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002613 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002615 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002616 }
Mike Stump11289f42009-09-09 15:08:12 +00002617
Douglas Gregor29c42f22012-02-24 07:38:34 +00002618 /// \brief Build a new type trait expression.
2619 ///
2620 /// By default, performs semantic analysis to build the new expression.
2621 /// Subclasses may override this routine to provide different behavior.
2622 ExprResult RebuildTypeTrait(TypeTrait Trait,
2623 SourceLocation StartLoc,
2624 ArrayRef<TypeSourceInfo *> Args,
2625 SourceLocation RParenLoc) {
2626 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2627 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002628
John Wiegley6242b6a2011-04-28 00:16:57 +00002629 /// \brief Build a new array type trait expression.
2630 ///
2631 /// By default, performs semantic analysis to build the new expression.
2632 /// Subclasses may override this routine to provide different behavior.
2633 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2634 SourceLocation StartLoc,
2635 TypeSourceInfo *TSInfo,
2636 Expr *DimExpr,
2637 SourceLocation RParenLoc) {
2638 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2639 }
2640
John Wiegleyf9f65842011-04-25 06:54:41 +00002641 /// \brief Build a new expression trait expression.
2642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
2645 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2646 SourceLocation StartLoc,
2647 Expr *Queried,
2648 SourceLocation RParenLoc) {
2649 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2650 }
2651
Mike Stump11289f42009-09-09 15:08:12 +00002652 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 /// expression.
2654 ///
2655 /// By default, performs semantic analysis to build the new expression.
2656 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002657 ExprResult RebuildDependentScopeDeclRefExpr(
2658 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002659 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002660 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002661 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002662 bool IsAddressOfOperand,
2663 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002664 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002665 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002666
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002667 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002668 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2669 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002670
Reid Kleckner32506ed2014-06-12 23:03:48 +00002671 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002672 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 }
2674
2675 /// \brief Build a new template-id expression.
2676 ///
2677 /// By default, performs semantic analysis to build the new expression.
2678 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002679 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002680 SourceLocation TemplateKWLoc,
2681 LookupResult &R,
2682 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002683 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002684 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2685 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002686 }
2687
2688 /// \brief Build a new object-construction expression.
2689 ///
2690 /// By default, performs semantic analysis to build the new expression.
2691 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002692 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002693 SourceLocation Loc,
2694 CXXConstructorDecl *Constructor,
2695 bool IsElidable,
2696 MultiExprArg Args,
2697 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002698 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002699 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002700 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002701 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002702 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002703 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002704 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002705 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002706 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002707
Richard Smithc83bf822016-06-10 00:58:19 +00002708 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002709 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002710 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002711 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002712 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002713 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002714 RequiresZeroInit, ConstructKind,
2715 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 }
2717
Richard Smith5179eb72016-06-28 19:03:57 +00002718 /// \brief Build a new implicit construction via inherited constructor
2719 /// expression.
2720 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2721 CXXConstructorDecl *Constructor,
2722 bool ConstructsVBase,
2723 bool InheritedFromVBase) {
2724 return new (getSema().Context) CXXInheritedCtorInitExpr(
2725 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2726 }
2727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 /// \brief Build a new object-construction expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002732 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2733 SourceLocation LParenLoc,
2734 MultiExprArg Args,
2735 SourceLocation RParenLoc) {
2736 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002738 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002739 RParenLoc);
2740 }
2741
2742 /// \brief Build a new object-construction expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002746 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2747 SourceLocation LParenLoc,
2748 MultiExprArg Args,
2749 SourceLocation RParenLoc) {
2750 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002751 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002752 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002753 RParenLoc);
2754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 /// \brief Build a new member reference expression.
2757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002760 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002761 QualType BaseType,
2762 bool IsArrow,
2763 SourceLocation OperatorLoc,
2764 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002765 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002766 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002767 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002768 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002769 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002770 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002771
John McCallb268a282010-08-23 23:25:46 +00002772 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002773 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002774 SS, TemplateKWLoc,
2775 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002776 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002777 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002778 }
2779
John McCall10eae182009-11-30 22:42:35 +00002780 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002784 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2785 SourceLocation OperatorLoc,
2786 bool IsArrow,
2787 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002788 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002789 NamedDecl *FirstQualifierInScope,
2790 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002791 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002792 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002793 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002794
John McCallb268a282010-08-23 23:25:46 +00002795 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002796 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002797 SS, TemplateKWLoc,
2798 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002799 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002800 }
Mike Stump11289f42009-09-09 15:08:12 +00002801
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002802 /// \brief Build a new noexcept expression.
2803 ///
2804 /// By default, performs semantic analysis to build the new expression.
2805 /// Subclasses may override this routine to provide different behavior.
2806 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2807 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2808 }
2809
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002810 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002811 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2812 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002813 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002814 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002815 Optional<unsigned> Length,
2816 ArrayRef<TemplateArgument> PartialArgs) {
2817 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2818 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002819 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002820
Patrick Beard0caa3942012-04-19 00:25:12 +00002821 /// \brief Build a new Objective-C boxed expression.
2822 ///
2823 /// By default, performs semantic analysis to build the new expression.
2824 /// Subclasses may override this routine to provide different behavior.
2825 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2826 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002828
Ted Kremeneke65b0862012-03-06 20:05:56 +00002829 /// \brief Build a new Objective-C array literal.
2830 ///
2831 /// By default, performs semantic analysis to build the new expression.
2832 /// Subclasses may override this routine to provide different behavior.
2833 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2834 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002835 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002836 MultiExprArg(Elements, NumElements));
2837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002838
2839 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002840 Expr *Base, Expr *Key,
2841 ObjCMethodDecl *getterMethod,
2842 ObjCMethodDecl *setterMethod) {
2843 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2844 getterMethod, setterMethod);
2845 }
2846
2847 /// \brief Build a new Objective-C dictionary literal.
2848 ///
2849 /// By default, performs semantic analysis to build the new expression.
2850 /// Subclasses may override this routine to provide different behavior.
2851 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002852 MutableArrayRef<ObjCDictionaryElement> Elements) {
2853 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002855
James Dennett2a4d13c2012-06-15 07:13:21 +00002856 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002857 ///
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002860 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002861 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002862 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002863 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002864 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002865
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002866 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002867 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002868 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002869 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002870 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002871 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002872 MultiExprArg Args,
2873 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002874 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2875 ReceiverTypeInfo->getType(),
2876 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002877 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002878 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002879 }
2880
2881 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002882 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002883 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002884 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002885 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002886 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002887 MultiExprArg Args,
2888 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002889 return SemaRef.BuildInstanceMessage(Receiver,
2890 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002891 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002892 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002893 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002894 }
2895
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002896 /// \brief Build a new Objective-C instance/class message to 'super'.
2897 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2898 Selector Sel,
2899 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002900 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002901 ObjCMethodDecl *Method,
2902 SourceLocation LBracLoc,
2903 MultiExprArg Args,
2904 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002905 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002906 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002907 SuperLoc,
2908 Sel, Method, LBracLoc, SelectorLocs,
2909 RBracLoc, Args)
2910 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002911 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002912 SuperLoc,
2913 Sel, Method, LBracLoc, SelectorLocs,
2914 RBracLoc, Args);
2915
2916
2917 }
2918
Douglas Gregord51d90d2010-04-26 20:11:03 +00002919 /// \brief Build a new Objective-C ivar reference expression.
2920 ///
2921 /// By default, performs semantic analysis to build the new expression.
2922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002923 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002924 SourceLocation IvarLoc,
2925 bool IsArrow, bool IsFreeIvar) {
2926 // FIXME: We lose track of the IsFreeIvar bit.
2927 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002928 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2929 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002930 /*FIXME:*/IvarLoc, IsArrow,
2931 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002932 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002933 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002934 /*TemplateArgs=*/nullptr,
2935 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002936 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002937
2938 /// \brief Build a new Objective-C property reference expression.
2939 ///
2940 /// By default, performs semantic analysis to build the new expression.
2941 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002942 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002943 ObjCPropertyDecl *Property,
2944 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002945 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002946 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2947 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2948 /*FIXME:*/PropertyLoc,
2949 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002950 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002951 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002952 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002953 /*TemplateArgs=*/nullptr,
2954 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002956
John McCallb7bd14f2010-12-02 01:19:52 +00002957 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002958 ///
2959 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002960 /// Subclasses may override this routine to provide different behavior.
2961 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2962 ObjCMethodDecl *Getter,
2963 ObjCMethodDecl *Setter,
2964 SourceLocation PropertyLoc) {
2965 // Since these expressions can only be value-dependent, we do not
2966 // need to perform semantic analysis again.
2967 return Owned(
2968 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2969 VK_LValue, OK_ObjCProperty,
2970 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002971 }
2972
Douglas Gregord51d90d2010-04-26 20:11:03 +00002973 /// \brief Build a new Objective-C "isa" expression.
2974 ///
2975 /// By default, performs semantic analysis to build the new expression.
2976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002977 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002978 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002979 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002980 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2981 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002982 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002983 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002984 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002985 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002986 /*TemplateArgs=*/nullptr,
2987 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregora16548e2009-08-11 05:31:07 +00002990 /// \brief Build a new shuffle vector expression.
2991 ///
2992 /// By default, performs semantic analysis to build the new expression.
2993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002994 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002995 MultiExprArg SubExprs,
2996 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002997 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002998 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002999 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3000 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3001 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003002 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003003
Douglas Gregora16548e2009-08-11 05:31:07 +00003004 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003005 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003006 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3007 SemaRef.Context.BuiltinFnTy,
3008 VK_RValue, BuiltinLoc);
3009 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3010 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003011 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003012
3013 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003014 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003015 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003016 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregora16548e2009-08-11 05:31:07 +00003018 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003019 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003020 }
John McCall31f82722010-11-12 08:19:04 +00003021
Hal Finkelc4d7c822013-09-18 03:29:45 +00003022 /// \brief Build a new convert vector expression.
3023 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3024 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3025 SourceLocation RParenLoc) {
3026 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3027 BuiltinLoc, RParenLoc);
3028 }
3029
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003030 /// \brief Build a new template argument pack expansion.
3031 ///
3032 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003033 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 /// different behavior.
3035 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003036 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003037 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003038 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003039 case TemplateArgument::Expression: {
3040 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003041 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3042 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003043 if (Result.isInvalid())
3044 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregor98318c22011-01-03 21:37:45 +00003046 return TemplateArgumentLoc(Result.get(), Result.get());
3047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003049 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003050 return TemplateArgumentLoc(TemplateArgument(
3051 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003052 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003053 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003054 Pattern.getTemplateNameLoc(),
3055 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003056
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003057 case TemplateArgument::Null:
3058 case TemplateArgument::Integral:
3059 case TemplateArgument::Declaration:
3060 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003061 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003062 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003063 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003065 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003066 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003068 EllipsisLoc,
3069 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3071 Expansion);
3072 break;
3073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003075 return TemplateArgumentLoc();
3076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor968f23a2011-01-03 19:31:53 +00003078 /// \brief Build a new expression pack expansion.
3079 ///
3080 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003081 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003082 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003083 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003084 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003085 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003087
Richard Smith0f0af192014-11-08 05:07:16 +00003088 /// \brief Build a new C++1z fold-expression.
3089 ///
3090 /// By default, performs semantic analysis in order to build a new fold
3091 /// expression.
3092 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3093 BinaryOperatorKind Operator,
3094 SourceLocation EllipsisLoc, Expr *RHS,
3095 SourceLocation RParenLoc) {
3096 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3097 RHS, RParenLoc);
3098 }
3099
3100 /// \brief Build an empty C++1z fold-expression with the given operator.
3101 ///
3102 /// By default, produces the fallback value for the fold-expression, or
3103 /// produce an error if there is no fallback value.
3104 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3105 BinaryOperatorKind Operator) {
3106 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3107 }
3108
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003109 /// \brief Build a new atomic operation expression.
3110 ///
3111 /// By default, performs semantic analysis to build the new expression.
3112 /// Subclasses may override this routine to provide different behavior.
3113 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3114 MultiExprArg SubExprs,
3115 QualType RetTy,
3116 AtomicExpr::AtomicOp Op,
3117 SourceLocation RParenLoc) {
3118 // Just create the expression; there is not any interesting semantic
3119 // analysis here because we can't actually build an AtomicExpr until
3120 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003121 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003122 RParenLoc);
3123 }
3124
John McCall31f82722010-11-12 08:19:04 +00003125private:
Douglas Gregor14454802011-02-25 02:25:35 +00003126 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3127 QualType ObjectType,
3128 NamedDecl *FirstQualifierInScope,
3129 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003130
3131 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3132 QualType ObjectType,
3133 NamedDecl *FirstQualifierInScope,
3134 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003135
3136 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3137 NamedDecl *FirstQualifierInScope,
3138 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139};
Douglas Gregora16548e2009-08-11 05:31:07 +00003140
Douglas Gregorebe10102009-08-20 07:17:43 +00003141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003142StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003144 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 switch (S->getStmtClass()) {
3147 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregorebe10102009-08-20 07:17:43 +00003149 // Transform individual statement nodes
3150#define STMT(Node, Parent) \
3151 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003152#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003153#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003154#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156 // Transform expressions by calling TransformExpr.
3157#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003158#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003159#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003160#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003161 {
John McCalldadc5752010-08-24 06:29:42 +00003162 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003164 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003165
Richard Smith945f8d32013-01-14 22:39:08 +00003166 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003167 }
Mike Stump11289f42009-09-09 15:08:12 +00003168 }
3169
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003170 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003171}
Mike Stump11289f42009-09-09 15:08:12 +00003172
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003173template<typename Derived>
3174OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3175 if (!S)
3176 return S;
3177
3178 switch (S->getClauseKind()) {
3179 default: break;
3180 // Transform individual clause nodes
3181#define OPENMP_CLAUSE(Name, Class) \
3182 case OMPC_ ## Name : \
3183 return getDerived().Transform ## Class(cast<Class>(S));
3184#include "clang/Basic/OpenMPKinds.def"
3185 }
3186
3187 return S;
3188}
3189
Mike Stump11289f42009-09-09 15:08:12 +00003190
Douglas Gregore922c772009-08-04 22:27:00 +00003191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003192ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003193 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003194 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003195
3196 switch (E->getStmtClass()) {
3197 case Stmt::NoStmtClass: break;
3198#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003199#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003200#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003201 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003202#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003203 }
3204
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003205 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003206}
3207
3208template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003209ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003210 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003211 // Initializers are instantiated like expressions, except that various outer
3212 // layers are stripped.
3213 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003214 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003215
3216 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3217 Init = ExprTemp->getSubExpr();
3218
Richard Smithe6ca4752013-05-30 22:40:16 +00003219 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3220 Init = MTE->GetTemporaryExpr();
3221
Richard Smithd59b8322012-12-19 01:39:02 +00003222 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3223 Init = Binder->getSubExpr();
3224
3225 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3226 Init = ICE->getSubExprAsWritten();
3227
Richard Smithcc1b96d2013-06-12 22:31:48 +00003228 if (CXXStdInitializerListExpr *ILE =
3229 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003230 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003231
Richard Smithc6abd962014-07-25 01:12:44 +00003232 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003233 // InitListExprs. Other forms of copy-initialization will be a no-op if
3234 // the initializer is already the right type.
3235 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003236 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003237 return getDerived().TransformExpr(Init);
3238
3239 // Revert value-initialization back to empty parens.
3240 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3241 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003242 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003243 Parens.getEnd());
3244 }
3245
3246 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3247 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003248 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003249 SourceLocation());
3250
3251 // Revert initialization by constructor back to a parenthesized or braced list
3252 // of expressions. Any other form of initializer can just be reused directly.
3253 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003254 return getDerived().TransformExpr(Init);
3255
Richard Smithf8adcdc2014-07-17 05:12:35 +00003256 // If the initialization implicitly converted an initializer list to a
3257 // std::initializer_list object, unwrap the std::initializer_list too.
3258 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003259 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003260
Richard Smithd59b8322012-12-19 01:39:02 +00003261 SmallVector<Expr*, 8> NewArgs;
3262 bool ArgChanged = false;
3263 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003264 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003265 return ExprError();
3266
3267 // If this was list initialization, revert to list form.
3268 if (Construct->isListInitialization())
3269 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3270 Construct->getLocEnd(),
3271 Construct->getType());
3272
Richard Smithd59b8322012-12-19 01:39:02 +00003273 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003274 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003275 if (Parens.isInvalid()) {
3276 // This was a variable declaration's initialization for which no initializer
3277 // was specified.
3278 assert(NewArgs.empty() &&
3279 "no parens or braces but have direct init with arguments?");
3280 return ExprEmpty();
3281 }
Richard Smithd59b8322012-12-19 01:39:02 +00003282 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3283 Parens.getEnd());
3284}
3285
3286template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003287bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003288 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003289 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003290 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003291 bool *ArgChanged) {
3292 for (unsigned I = 0; I != NumInputs; ++I) {
3293 // If requested, drop call arguments that need to be dropped.
3294 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3295 if (ArgChanged)
3296 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregora3efea12011-01-03 19:04:46 +00003298 break;
3299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor968f23a2011-01-03 19:31:53 +00003301 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3302 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Chris Lattner01cf8db2011-07-20 06:58:45 +00003304 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003305 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3306 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003307
Douglas Gregor968f23a2011-01-03 19:31:53 +00003308 // Determine whether the set of unexpanded parameter packs can and should
3309 // be expanded.
3310 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003311 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003312 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3313 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003314 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3315 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003316 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003317 Expand, RetainExpansion,
3318 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003319 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003320
Douglas Gregor968f23a2011-01-03 19:31:53 +00003321 if (!Expand) {
3322 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003323 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003324 // expansion.
3325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3326 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3327 if (OutPattern.isInvalid())
3328 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
3330 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003331 Expansion->getEllipsisLoc(),
3332 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003333 if (Out.isInvalid())
3334 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor968f23a2011-01-03 19:31:53 +00003336 if (ArgChanged)
3337 *ArgChanged = true;
3338 Outputs.push_back(Out.get());
3339 continue;
3340 }
John McCall542e7c62011-07-06 07:30:07 +00003341
3342 // Record right away that the argument was changed. This needs
3343 // to happen even if the array expands to nothing.
3344 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor968f23a2011-01-03 19:31:53 +00003346 // The transform has determined that we should perform an elementwise
3347 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003348 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003349 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3350 ExprResult Out = getDerived().TransformExpr(Pattern);
3351 if (Out.isInvalid())
3352 return true;
3353
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003354 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003355 Out = getDerived().RebuildPackExpansion(
3356 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003357 if (Out.isInvalid())
3358 return true;
3359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor968f23a2011-01-03 19:31:53 +00003361 Outputs.push_back(Out.get());
3362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Richard Smith9467be42014-06-06 17:33:35 +00003364 // If we're supposed to retain a pack expansion, do so by temporarily
3365 // forgetting the partially-substituted parameter pack.
3366 if (RetainExpansion) {
3367 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3368
3369 ExprResult Out = getDerived().TransformExpr(Pattern);
3370 if (Out.isInvalid())
3371 return true;
3372
3373 Out = getDerived().RebuildPackExpansion(
3374 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3375 if (Out.isInvalid())
3376 return true;
3377
3378 Outputs.push_back(Out.get());
3379 }
3380
Douglas Gregor968f23a2011-01-03 19:31:53 +00003381 continue;
3382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003383
Richard Smithd59b8322012-12-19 01:39:02 +00003384 ExprResult Result =
3385 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3386 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003387 if (Result.isInvalid())
3388 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Douglas Gregora3efea12011-01-03 19:04:46 +00003390 if (Result.get() != Inputs[I] && ArgChanged)
3391 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
3393 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Douglas Gregora3efea12011-01-03 19:04:46 +00003396 return false;
3397}
3398
Richard Smith03a4aa32016-06-23 19:02:52 +00003399template <typename Derived>
3400Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3401 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3402 if (Var) {
3403 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3404 getDerived().TransformDefinition(Var->getLocation(), Var));
3405
3406 if (!ConditionVar)
3407 return Sema::ConditionError();
3408
3409 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3410 }
3411
3412 if (Expr) {
3413 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3414
3415 if (CondExpr.isInvalid())
3416 return Sema::ConditionError();
3417
3418 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3419 }
3420
3421 return Sema::ConditionResult();
3422}
3423
Douglas Gregora3efea12011-01-03 19:04:46 +00003424template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003425NestedNameSpecifierLoc
3426TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3427 NestedNameSpecifierLoc NNS,
3428 QualType ObjectType,
3429 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003430 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003431 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003432 Qualifier = Qualifier.getPrefix())
3433 Qualifiers.push_back(Qualifier);
3434
3435 CXXScopeSpec SS;
3436 while (!Qualifiers.empty()) {
3437 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3438 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor14454802011-02-25 02:25:35 +00003440 switch (QNNS->getKind()) {
3441 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003442 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003443 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003444 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003445 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003446 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003447 FirstQualifierInScope, false))
3448 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregor14454802011-02-25 02:25:35 +00003450 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor14454802011-02-25 02:25:35 +00003452 case NestedNameSpecifier::Namespace: {
3453 NamespaceDecl *NS
3454 = cast_or_null<NamespaceDecl>(
3455 getDerived().TransformDecl(
3456 Q.getLocalBeginLoc(),
3457 QNNS->getAsNamespace()));
3458 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3459 break;
3460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregor14454802011-02-25 02:25:35 +00003462 case NestedNameSpecifier::NamespaceAlias: {
3463 NamespaceAliasDecl *Alias
3464 = cast_or_null<NamespaceAliasDecl>(
3465 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3466 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003467 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003468 Q.getLocalEndLoc());
3469 break;
3470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003471
Douglas Gregor14454802011-02-25 02:25:35 +00003472 case NestedNameSpecifier::Global:
3473 // There is no meaningful transformation that one could perform on the
3474 // global scope.
3475 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3476 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Nikola Smiljanic67860242014-09-26 00:28:20 +00003478 case NestedNameSpecifier::Super: {
3479 CXXRecordDecl *RD =
3480 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3481 SourceLocation(), QNNS->getAsRecordDecl()));
3482 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3483 break;
3484 }
3485
Douglas Gregor14454802011-02-25 02:25:35 +00003486 case NestedNameSpecifier::TypeSpecWithTemplate:
3487 case NestedNameSpecifier::TypeSpec: {
3488 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3489 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor14454802011-02-25 02:25:35 +00003491 if (!TL)
3492 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregor14454802011-02-25 02:25:35 +00003494 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003495 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003496 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003497 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003498 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003499 if (TL.getType()->isEnumeralType())
3500 SemaRef.Diag(TL.getBeginLoc(),
3501 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003502 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3503 Q.getLocalEndLoc());
3504 break;
3505 }
Richard Trieude756fb2011-05-07 01:36:37 +00003506 // If the nested-name-specifier is an invalid type def, don't emit an
3507 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003508 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3509 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003510 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003511 << TL.getType() << SS.getRange();
3512 }
Douglas Gregor14454802011-02-25 02:25:35 +00003513 return NestedNameSpecifierLoc();
3514 }
Douglas Gregore16af532011-02-28 18:50:33 +00003515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregore16af532011-02-28 18:50:33 +00003517 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003518 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003519 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003520 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor14454802011-02-25 02:25:35 +00003522 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003523 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003524 !getDerived().AlwaysRebuild())
3525 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003526
3527 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003528 // nested-name-specifier, do so.
3529 if (SS.location_size() == NNS.getDataLength() &&
3530 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3531 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3532
3533 // Allocate new nested-name-specifier location information.
3534 return SS.getWithLocInContext(SemaRef.Context);
3535}
3536
3537template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003538DeclarationNameInfo
3539TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003540::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003541 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003542 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003543 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003544
3545 switch (Name.getNameKind()) {
3546 case DeclarationName::Identifier:
3547 case DeclarationName::ObjCZeroArgSelector:
3548 case DeclarationName::ObjCOneArgSelector:
3549 case DeclarationName::ObjCMultiArgSelector:
3550 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003551 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003552 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003553 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorf816bd72009-09-03 22:13:48 +00003555 case DeclarationName::CXXConstructorName:
3556 case DeclarationName::CXXDestructorName:
3557 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003558 TypeSourceInfo *NewTInfo;
3559 CanQualType NewCanTy;
3560 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003561 NewTInfo = getDerived().TransformType(OldTInfo);
3562 if (!NewTInfo)
3563 return DeclarationNameInfo();
3564 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003565 }
3566 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003567 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003568 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003569 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003570 if (NewT.isNull())
3571 return DeclarationNameInfo();
3572 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3573 }
Mike Stump11289f42009-09-09 15:08:12 +00003574
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003575 DeclarationName NewName
3576 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3577 NewCanTy);
3578 DeclarationNameInfo NewNameInfo(NameInfo);
3579 NewNameInfo.setName(NewName);
3580 NewNameInfo.setNamedTypeInfo(NewTInfo);
3581 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003582 }
Mike Stump11289f42009-09-09 15:08:12 +00003583 }
3584
David Blaikie83d382b2011-09-23 05:06:16 +00003585 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003586}
3587
3588template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003589TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003590TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3591 TemplateName Name,
3592 SourceLocation NameLoc,
3593 QualType ObjectType,
3594 NamedDecl *FirstQualifierInScope) {
3595 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3596 TemplateDecl *Template = QTN->getTemplateDecl();
3597 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003598
Douglas Gregor9db53502011-03-02 18:07:45 +00003599 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003600 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003601 Template));
3602 if (!TransTemplate)
3603 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor9db53502011-03-02 18:07:45 +00003605 if (!getDerived().AlwaysRebuild() &&
3606 SS.getScopeRep() == QTN->getQualifier() &&
3607 TransTemplate == Template)
3608 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregor9db53502011-03-02 18:07:45 +00003610 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3611 TransTemplate);
3612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor9db53502011-03-02 18:07:45 +00003614 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3615 if (SS.getScopeRep()) {
3616 // These apply to the scope specifier, not the template.
3617 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003618 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003619 }
3620
Douglas Gregor9db53502011-03-02 18:07:45 +00003621 if (!getDerived().AlwaysRebuild() &&
3622 SS.getScopeRep() == DTN->getQualifier() &&
3623 ObjectType.isNull())
3624 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Douglas Gregor9db53502011-03-02 18:07:45 +00003626 if (DTN->isIdentifier()) {
3627 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003628 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003629 NameLoc,
3630 ObjectType,
3631 FirstQualifierInScope);
3632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003633
Douglas Gregor9db53502011-03-02 18:07:45 +00003634 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3635 ObjectType);
3636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor9db53502011-03-02 18:07:45 +00003638 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3639 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003640 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003641 Template));
3642 if (!TransTemplate)
3643 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregor9db53502011-03-02 18:07:45 +00003645 if (!getDerived().AlwaysRebuild() &&
3646 TransTemplate == Template)
3647 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor9db53502011-03-02 18:07:45 +00003649 return TemplateName(TransTemplate);
3650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
Douglas Gregor9db53502011-03-02 18:07:45 +00003652 if (SubstTemplateTemplateParmPackStorage *SubstPack
3653 = Name.getAsSubstTemplateTemplateParmPack()) {
3654 TemplateTemplateParmDecl *TransParam
3655 = cast_or_null<TemplateTemplateParmDecl>(
3656 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3657 if (!TransParam)
3658 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregor9db53502011-03-02 18:07:45 +00003660 if (!getDerived().AlwaysRebuild() &&
3661 TransParam == SubstPack->getParameterPack())
3662 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
3664 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003665 SubstPack->getArgumentPack());
3666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor9db53502011-03-02 18:07:45 +00003668 // These should be getting filtered out before they reach the AST.
3669 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003670}
3671
3672template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003673void TreeTransform<Derived>::InventTemplateArgumentLoc(
3674 const TemplateArgument &Arg,
3675 TemplateArgumentLoc &Output) {
3676 SourceLocation Loc = getDerived().getBaseLocation();
3677 switch (Arg.getKind()) {
3678 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003679 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003680 break;
3681
3682 case TemplateArgument::Type:
3683 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003684 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003685
John McCall0ad16662009-10-29 08:12:44 +00003686 break;
3687
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003688 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003689 case TemplateArgument::TemplateExpansion: {
3690 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003691 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003692 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3693 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3694 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3695 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
Douglas Gregor9d802122011-03-02 17:09:35 +00003697 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003698 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003699 Builder.getWithLocInContext(SemaRef.Context),
3700 Loc);
3701 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003702 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003703 Builder.getWithLocInContext(SemaRef.Context),
3704 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003706 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003707 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003708
John McCall0ad16662009-10-29 08:12:44 +00003709 case TemplateArgument::Expression:
3710 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3711 break;
3712
3713 case TemplateArgument::Declaration:
3714 case TemplateArgument::Integral:
3715 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003716 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003717 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003718 break;
3719 }
3720}
3721
3722template<typename Derived>
3723bool TreeTransform<Derived>::TransformTemplateArgument(
3724 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003725 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003726 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003727 switch (Arg.getKind()) {
3728 case TemplateArgument::Null:
3729 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003730 case TemplateArgument::Pack:
3731 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003732 case TemplateArgument::NullPtr:
3733 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregore922c772009-08-04 22:27:00 +00003735 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003736 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003737 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003738 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003739
3740 DI = getDerived().TransformType(DI);
3741 if (!DI) return true;
3742
3743 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3744 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003745 }
Mike Stump11289f42009-09-09 15:08:12 +00003746
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003747 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003748 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3749 if (QualifierLoc) {
3750 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3751 if (!QualifierLoc)
3752 return true;
3753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003754
Douglas Gregordf846d12011-03-02 18:46:51 +00003755 CXXScopeSpec SS;
3756 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003757 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003758 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3759 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003760 if (Template.isNull())
3761 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003762
Douglas Gregor9d802122011-03-02 17:09:35 +00003763 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003764 Input.getTemplateNameLoc());
3765 return false;
3766 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003767
3768 case TemplateArgument::TemplateExpansion:
3769 llvm_unreachable("Caller should expand pack expansions");
3770
Douglas Gregore922c772009-08-04 22:27:00 +00003771 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003772 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003773 EnterExpressionEvaluationContext Unevaluated(
3774 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003775
John McCall0ad16662009-10-29 08:12:44 +00003776 Expr *InputExpr = Input.getSourceExpression();
3777 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3778
Chris Lattnercdb591a2011-04-25 20:37:58 +00003779 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003780 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003781 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003782 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003783 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003784 }
Douglas Gregore922c772009-08-04 22:27:00 +00003785 }
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregore922c772009-08-04 22:27:00 +00003787 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003788 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003789}
3790
Douglas Gregorfe921a72010-12-20 23:36:19 +00003791/// \brief Iterator adaptor that invents template argument location information
3792/// for each of the template arguments in its underlying iterator.
3793template<typename Derived, typename InputIterator>
3794class TemplateArgumentLocInventIterator {
3795 TreeTransform<Derived> &Self;
3796 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
Douglas Gregorfe921a72010-12-20 23:36:19 +00003798public:
3799 typedef TemplateArgumentLoc value_type;
3800 typedef TemplateArgumentLoc reference;
3801 typedef typename std::iterator_traits<InputIterator>::difference_type
3802 difference_type;
3803 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003804
Douglas Gregorfe921a72010-12-20 23:36:19 +00003805 class pointer {
3806 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003807
Douglas Gregorfe921a72010-12-20 23:36:19 +00003808 public:
3809 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
Douglas Gregorfe921a72010-12-20 23:36:19 +00003811 const TemplateArgumentLoc *operator->() const { return &Arg; }
3812 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003814 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003815
Douglas Gregorfe921a72010-12-20 23:36:19 +00003816 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3817 InputIterator Iter)
3818 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003819
Douglas Gregorfe921a72010-12-20 23:36:19 +00003820 TemplateArgumentLocInventIterator &operator++() {
3821 ++Iter;
3822 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Douglas Gregorfe921a72010-12-20 23:36:19 +00003825 TemplateArgumentLocInventIterator operator++(int) {
3826 TemplateArgumentLocInventIterator Old(*this);
3827 ++(*this);
3828 return Old;
3829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
Douglas Gregorfe921a72010-12-20 23:36:19 +00003831 reference operator*() const {
3832 TemplateArgumentLoc Result;
3833 Self.InventTemplateArgumentLoc(*Iter, Result);
3834 return Result;
3835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Douglas Gregorfe921a72010-12-20 23:36:19 +00003837 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003838
Douglas Gregorfe921a72010-12-20 23:36:19 +00003839 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3840 const TemplateArgumentLocInventIterator &Y) {
3841 return X.Iter == Y.Iter;
3842 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003843
Douglas Gregorfe921a72010-12-20 23:36:19 +00003844 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3845 const TemplateArgumentLocInventIterator &Y) {
3846 return X.Iter != Y.Iter;
3847 }
3848};
Chad Rosier1dcde962012-08-08 18:46:20 +00003849
Douglas Gregor42cafa82010-12-20 17:42:22 +00003850template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003851template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003852bool TreeTransform<Derived>::TransformTemplateArguments(
3853 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3854 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003855 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003856 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003857 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003858
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003859 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3860 // Unpack argument packs, which we translate them into separate
3861 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003862 // FIXME: We could do much better if we could guarantee that the
3863 // TemplateArgumentLocInfo for the pack expansion would be usable for
3864 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003865 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003866 TemplateArgument::pack_iterator>
3867 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003868 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003869 In.getArgument().pack_begin()),
3870 PackLocIterator(*this,
3871 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003872 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003873 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003874
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003875 continue;
3876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003878 if (In.getArgument().isPackExpansion()) {
3879 // We have a pack expansion, for which we will be substituting into
3880 // the pattern.
3881 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003882 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003883 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003884 = getSema().getTemplateArgumentPackExpansionPattern(
3885 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003886
Chris Lattner01cf8db2011-07-20 06:58:45 +00003887 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003888 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3889 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003891 // Determine whether the set of unexpanded parameter packs can and should
3892 // be expanded.
3893 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003894 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003895 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003896 if (getDerived().TryExpandParameterPacks(Ellipsis,
3897 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003898 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003899 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900 RetainExpansion,
3901 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003902 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003904 if (!Expand) {
3905 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003906 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003907 // expansion.
3908 TemplateArgumentLoc OutPattern;
3909 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003910 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003911 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003912
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003913 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3914 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003915 if (Out.getArgument().isNull())
3916 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003917
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003918 Outputs.addArgument(Out);
3919 continue;
3920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003921
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003922 // The transform has determined that we should perform an elementwise
3923 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003924 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3926
Richard Smithd784e682015-09-23 21:41:42 +00003927 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003928 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003930 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003931 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3932 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003933 if (Out.getArgument().isNull())
3934 return true;
3935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003937 Outputs.addArgument(Out);
3938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003939
Douglas Gregor48d24112011-01-10 20:53:55 +00003940 // If we're supposed to retain a pack expansion, do so by temporarily
3941 // forgetting the partially-substituted parameter pack.
3942 if (RetainExpansion) {
3943 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003944
Richard Smithd784e682015-09-23 21:41:42 +00003945 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003946 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003947
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003948 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3949 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003950 if (Out.getArgument().isNull())
3951 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003952
Douglas Gregor48d24112011-01-10 20:53:55 +00003953 Outputs.addArgument(Out);
3954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003956 continue;
3957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
3959 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003960 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003961 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003962
Douglas Gregor42cafa82010-12-20 17:42:22 +00003963 Outputs.addArgument(Out);
3964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003965
Douglas Gregor42cafa82010-12-20 17:42:22 +00003966 return false;
3967
3968}
3969
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970//===----------------------------------------------------------------------===//
3971// Type transformation
3972//===----------------------------------------------------------------------===//
3973
3974template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003975QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003976 if (getDerived().AlreadyTransformed(T))
3977 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003978
John McCall550e0c22009-10-21 00:40:46 +00003979 // Temporary workaround. All of these transformations should
3980 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003981 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3982 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003983
John McCall31f82722010-11-12 08:19:04 +00003984 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003985
John McCall550e0c22009-10-21 00:40:46 +00003986 if (!NewDI)
3987 return QualType();
3988
3989 return NewDI->getType();
3990}
3991
3992template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003993TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003994 // Refine the base location to the type's location.
3995 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3996 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003997 if (getDerived().AlreadyTransformed(DI->getType()))
3998 return DI;
3999
4000 TypeLocBuilder TLB;
4001
4002 TypeLoc TL = DI->getTypeLoc();
4003 TLB.reserve(TL.getFullDataSize());
4004
John McCall31f82722010-11-12 08:19:04 +00004005 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004006 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004007 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004008
John McCallbcd03502009-12-07 02:54:59 +00004009 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004010}
4011
4012template<typename Derived>
4013QualType
John McCall31f82722010-11-12 08:19:04 +00004014TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004015 switch (T.getTypeLocClass()) {
4016#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004017#define TYPELOC(CLASS, PARENT) \
4018 case TypeLoc::CLASS: \
4019 return getDerived().Transform##CLASS##Type(TLB, \
4020 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004021#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022 }
Mike Stump11289f42009-09-09 15:08:12 +00004023
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004024 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004025}
4026
4027/// FIXME: By default, this routine adds type qualifiers only to types
4028/// that can have qualifiers, and silently suppresses those qualifiers
4029/// that are not permitted (e.g., qualifiers on reference or function
4030/// types). This is the right thing for template instantiation, but
4031/// probably not for other clients.
4032template<typename Derived>
4033QualType
4034TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004035 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004036 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004037
John McCall31f82722010-11-12 08:19:04 +00004038 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004039 if (Result.isNull())
4040 return QualType();
4041
4042 // Silently suppress qualifiers if the result type can't be qualified.
4043 // FIXME: this is the right thing for template instantiation, but
4044 // probably not for other clients.
4045 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004047
John McCall31168b02011-06-15 23:02:42 +00004048 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004049 // resulting type.
4050 if (Quals.hasObjCLifetime()) {
4051 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4052 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004053 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004054 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004055 // A lifetime qualifier applied to a substituted template parameter
4056 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004057 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004058 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004059 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4060 QualType Replacement = SubstTypeParam->getReplacementType();
4061 Qualifiers Qs = Replacement.getQualifiers();
4062 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004063 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004064 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4065 Qs);
4066 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004067 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004068 Replacement);
4069 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004070 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4071 // 'auto' types behave the same way as template parameters.
4072 QualType Deduced = AutoTy->getDeducedType();
4073 Qualifiers Qs = Deduced.getQualifiers();
4074 Qs.removeObjCLifetime();
4075 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4076 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004077 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004078 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004079 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004080 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004081 // Otherwise, complain about the addition of a qualifier to an
4082 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004083 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004084 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004085 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004086
Douglas Gregore46db902011-06-17 22:11:49 +00004087 Quals.removeObjCLifetime();
4088 }
4089 }
4090 }
John McCallcb0f89a2010-06-05 06:41:15 +00004091 if (!Quals.empty()) {
4092 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004093 // BuildQualifiedType might not add qualifiers if they are invalid.
4094 if (Result.hasLocalQualifiers())
4095 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004096 // No location information to preserve.
4097 }
John McCall550e0c22009-10-21 00:40:46 +00004098
4099 return Result;
4100}
4101
Douglas Gregor14454802011-02-25 02:25:35 +00004102template<typename Derived>
4103TypeLoc
4104TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4105 QualType ObjectType,
4106 NamedDecl *UnqualLookup,
4107 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004108 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004109 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004111 TypeSourceInfo *TSI =
4112 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4113 if (TSI)
4114 return TSI->getTypeLoc();
4115 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004116}
4117
Douglas Gregor579c15f2011-03-02 18:32:08 +00004118template<typename Derived>
4119TypeSourceInfo *
4120TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4121 QualType ObjectType,
4122 NamedDecl *UnqualLookup,
4123 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004124 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004125 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004127 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4128 UnqualLookup, SS);
4129}
4130
4131template <typename Derived>
4132TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4133 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4134 CXXScopeSpec &SS) {
4135 QualType T = TL.getType();
4136 assert(!getDerived().AlreadyTransformed(T));
4137
Douglas Gregor579c15f2011-03-02 18:32:08 +00004138 TypeLocBuilder TLB;
4139 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004140
Douglas Gregor579c15f2011-03-02 18:32:08 +00004141 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004142 TemplateSpecializationTypeLoc SpecTL =
4143 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004144
Douglas Gregor579c15f2011-03-02 18:32:08 +00004145 TemplateName Template
4146 = getDerived().TransformTemplateName(SS,
4147 SpecTL.getTypePtr()->getTemplateName(),
4148 SpecTL.getTemplateNameLoc(),
4149 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004150 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004151 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004152
4153 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004154 Template);
4155 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004156 DependentTemplateSpecializationTypeLoc SpecTL =
4157 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004158
Douglas Gregor579c15f2011-03-02 18:32:08 +00004159 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004160 = getDerived().RebuildTemplateName(SS,
4161 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004162 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004163 ObjectType, UnqualLookup);
4164 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004165 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004166
4167 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004168 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004169 Template,
4170 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004171 } else {
4172 // Nothing special needs to be done for these.
4173 Result = getDerived().TransformType(TLB, TL);
4174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004175
4176 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004177 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004178
Douglas Gregor579c15f2011-03-02 18:32:08 +00004179 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4180}
4181
John McCall550e0c22009-10-21 00:40:46 +00004182template <class TyLoc> static inline
4183QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4184 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4185 NewT.setNameLoc(T.getNameLoc());
4186 return T.getType();
4187}
4188
John McCall550e0c22009-10-21 00:40:46 +00004189template<typename Derived>
4190QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004191 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004192 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4193 NewT.setBuiltinLoc(T.getBuiltinLoc());
4194 if (T.needsExtraLocalData())
4195 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4196 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004200QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004201 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004202 // FIXME: recurse?
4203 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Reid Kleckner0503a872013-12-05 01:23:43 +00004206template <typename Derived>
4207QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4208 AdjustedTypeLoc TL) {
4209 // Adjustments applied during transformation are handled elsewhere.
4210 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4211}
4212
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004214QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4215 DecayedTypeLoc TL) {
4216 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4217 if (OriginalType.isNull())
4218 return QualType();
4219
4220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() ||
4222 OriginalType != TL.getOriginalLoc().getType())
4223 Result = SemaRef.Context.getDecayedType(OriginalType);
4224 TLB.push<DecayedTypeLoc>(Result);
4225 // Nothing to set for DecayedTypeLoc.
4226 return Result;
4227}
4228
4229template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004230QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004232 QualType PointeeType
4233 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004234 if (PointeeType.isNull())
4235 return QualType();
4236
4237 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004238 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004239 // A dependent pointer type 'T *' has is being transformed such
4240 // that an Objective-C class type is being replaced for 'T'. The
4241 // resulting pointer type is an ObjCObjectPointerType, not a
4242 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004243 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004244
John McCall8b07ec22010-05-15 11:32:37 +00004245 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4246 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004247 return Result;
4248 }
John McCall31f82722010-11-12 08:19:04 +00004249
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004250 if (getDerived().AlwaysRebuild() ||
4251 PointeeType != TL.getPointeeLoc().getType()) {
4252 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4253 if (Result.isNull())
4254 return QualType();
4255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004256
John McCall31168b02011-06-15 23:02:42 +00004257 // Objective-C ARC can add lifetime qualifiers to the type that we're
4258 // pointing to.
4259 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004260
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004261 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4262 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004263 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004264}
Mike Stump11289f42009-09-09 15:08:12 +00004265
4266template<typename Derived>
4267QualType
John McCall550e0c22009-10-21 00:40:46 +00004268TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004269 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004270 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004271 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4272 if (PointeeType.isNull())
4273 return QualType();
4274
4275 QualType Result = TL.getType();
4276 if (getDerived().AlwaysRebuild() ||
4277 PointeeType != TL.getPointeeLoc().getType()) {
4278 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004279 TL.getSigilLoc());
4280 if (Result.isNull())
4281 return QualType();
4282 }
4283
Douglas Gregor049211a2010-04-22 16:50:51 +00004284 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004285 NewT.setSigilLoc(TL.getSigilLoc());
4286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004287}
4288
John McCall70dd5f62009-10-30 00:06:24 +00004289/// Transforms a reference type. Note that somewhat paradoxically we
4290/// don't care whether the type itself is an l-value type or an r-value
4291/// type; we only care if the type was *written* as an l-value type
4292/// or an r-value type.
4293template<typename Derived>
4294QualType
4295TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004296 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004297 const ReferenceType *T = TL.getTypePtr();
4298
4299 // Note that this works with the pointee-as-written.
4300 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4301 if (PointeeType.isNull())
4302 return QualType();
4303
4304 QualType Result = TL.getType();
4305 if (getDerived().AlwaysRebuild() ||
4306 PointeeType != T->getPointeeTypeAsWritten()) {
4307 Result = getDerived().RebuildReferenceType(PointeeType,
4308 T->isSpelledAsLValue(),
4309 TL.getSigilLoc());
4310 if (Result.isNull())
4311 return QualType();
4312 }
4313
John McCall31168b02011-06-15 23:02:42 +00004314 // Objective-C ARC can add lifetime qualifiers to the type that we're
4315 // referring to.
4316 TLB.TypeWasModifiedSafely(
4317 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4318
John McCall70dd5f62009-10-30 00:06:24 +00004319 // r-value references can be rebuilt as l-value references.
4320 ReferenceTypeLoc NewTL;
4321 if (isa<LValueReferenceType>(Result))
4322 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4323 else
4324 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4325 NewTL.setSigilLoc(TL.getSigilLoc());
4326
4327 return Result;
4328}
4329
Mike Stump11289f42009-09-09 15:08:12 +00004330template<typename Derived>
4331QualType
John McCall550e0c22009-10-21 00:40:46 +00004332TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004333 LValueReferenceTypeLoc TL) {
4334 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004335}
4336
Mike Stump11289f42009-09-09 15:08:12 +00004337template<typename Derived>
4338QualType
John McCall550e0c22009-10-21 00:40:46 +00004339TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004340 RValueReferenceTypeLoc TL) {
4341 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004342}
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregord6ff3322009-08-04 16:50:30 +00004344template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004345QualType
John McCall550e0c22009-10-21 00:40:46 +00004346TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004347 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004348 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004349 if (PointeeType.isNull())
4350 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004351
Abramo Bagnara509357842011-03-05 14:42:21 +00004352 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004353 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004354 if (OldClsTInfo) {
4355 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4356 if (!NewClsTInfo)
4357 return QualType();
4358 }
4359
4360 const MemberPointerType *T = TL.getTypePtr();
4361 QualType OldClsType = QualType(T->getClass(), 0);
4362 QualType NewClsType;
4363 if (NewClsTInfo)
4364 NewClsType = NewClsTInfo->getType();
4365 else {
4366 NewClsType = getDerived().TransformType(OldClsType);
4367 if (NewClsType.isNull())
4368 return QualType();
4369 }
Mike Stump11289f42009-09-09 15:08:12 +00004370
John McCall550e0c22009-10-21 00:40:46 +00004371 QualType Result = TL.getType();
4372 if (getDerived().AlwaysRebuild() ||
4373 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004374 NewClsType != OldClsType) {
4375 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004376 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004377 if (Result.isNull())
4378 return QualType();
4379 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004380
Reid Kleckner0503a872013-12-05 01:23:43 +00004381 // If we had to adjust the pointee type when building a member pointer, make
4382 // sure to push TypeLoc info for it.
4383 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4384 if (MPT && PointeeType != MPT->getPointeeType()) {
4385 assert(isa<AdjustedType>(MPT->getPointeeType()));
4386 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4387 }
4388
John McCall550e0c22009-10-21 00:40:46 +00004389 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4390 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004391 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004392
4393 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004394}
4395
Mike Stump11289f42009-09-09 15:08:12 +00004396template<typename Derived>
4397QualType
John McCall550e0c22009-10-21 00:40:46 +00004398TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004399 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004400 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004401 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402 if (ElementType.isNull())
4403 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004404
John McCall550e0c22009-10-21 00:40:46 +00004405 QualType Result = TL.getType();
4406 if (getDerived().AlwaysRebuild() ||
4407 ElementType != T->getElementType()) {
4408 Result = getDerived().RebuildConstantArrayType(ElementType,
4409 T->getSizeModifier(),
4410 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004411 T->getIndexTypeCVRQualifiers(),
4412 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004413 if (Result.isNull())
4414 return QualType();
4415 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004416
4417 // We might have either a ConstantArrayType or a VariableArrayType now:
4418 // a ConstantArrayType is allowed to have an element type which is a
4419 // VariableArrayType if the type is dependent. Fortunately, all array
4420 // types have the same location layout.
4421 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004422 NewTL.setLBracketLoc(TL.getLBracketLoc());
4423 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004424
John McCall550e0c22009-10-21 00:40:46 +00004425 Expr *Size = TL.getSizeExpr();
4426 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004427 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4428 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004429 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4430 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004431 }
4432 NewTL.setSizeExpr(Size);
4433
4434 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004435}
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregord6ff3322009-08-04 16:50:30 +00004437template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004438QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004439 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004440 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004441 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004442 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004443 if (ElementType.isNull())
4444 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004445
John McCall550e0c22009-10-21 00:40:46 +00004446 QualType Result = TL.getType();
4447 if (getDerived().AlwaysRebuild() ||
4448 ElementType != T->getElementType()) {
4449 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004450 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004451 T->getIndexTypeCVRQualifiers(),
4452 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004453 if (Result.isNull())
4454 return QualType();
4455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004456
John McCall550e0c22009-10-21 00:40:46 +00004457 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4458 NewTL.setLBracketLoc(TL.getLBracketLoc());
4459 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004460 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004461
4462 return Result;
4463}
4464
4465template<typename Derived>
4466QualType
4467TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004468 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004469 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004470 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4471 if (ElementType.isNull())
4472 return QualType();
4473
John McCalldadc5752010-08-24 06:29:42 +00004474 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004475 = getDerived().TransformExpr(T->getSizeExpr());
4476 if (SizeResult.isInvalid())
4477 return QualType();
4478
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004479 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 ElementType != T->getElementType() ||
4484 Size != T->getSizeExpr()) {
4485 Result = getDerived().RebuildVariableArrayType(ElementType,
4486 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004487 Size,
John McCall550e0c22009-10-21 00:40:46 +00004488 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004489 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004490 if (Result.isNull())
4491 return QualType();
4492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004493
Serge Pavlov774c6d02014-02-06 03:49:11 +00004494 // We might have constant size array now, but fortunately it has the same
4495 // location layout.
4496 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004497 NewTL.setLBracketLoc(TL.getLBracketLoc());
4498 NewTL.setRBracketLoc(TL.getRBracketLoc());
4499 NewTL.setSizeExpr(Size);
4500
4501 return Result;
4502}
4503
4504template<typename Derived>
4505QualType
4506TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004507 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004508 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004509 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4510 if (ElementType.isNull())
4511 return QualType();
4512
Richard Smith764d2fe2011-12-20 02:08:33 +00004513 // Array bounds are constant expressions.
4514 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4515 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004516
John McCall33ddac02011-01-19 10:06:00 +00004517 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4518 Expr *origSize = TL.getSizeExpr();
4519 if (!origSize) origSize = T->getSizeExpr();
4520
4521 ExprResult sizeResult
4522 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004523 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004524 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004525 return QualType();
4526
John McCall33ddac02011-01-19 10:06:00 +00004527 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004528
4529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004532 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004533 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4534 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004535 size,
John McCall550e0c22009-10-21 00:40:46 +00004536 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004537 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004538 if (Result.isNull())
4539 return QualType();
4540 }
John McCall550e0c22009-10-21 00:40:46 +00004541
4542 // We might have any sort of array type now, but fortunately they
4543 // all have the same location layout.
4544 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4545 NewTL.setLBracketLoc(TL.getLBracketLoc());
4546 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004547 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004548
4549 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004550}
Mike Stump11289f42009-09-09 15:08:12 +00004551
4552template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004554 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004555 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004556 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004557
4558 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559 QualType ElementType = getDerived().TransformType(T->getElementType());
4560 if (ElementType.isNull())
4561 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Richard Smith764d2fe2011-12-20 02:08:33 +00004563 // Vector sizes are constant expressions.
4564 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4565 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004566
John McCalldadc5752010-08-24 06:29:42 +00004567 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004568 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569 if (Size.isInvalid())
4570 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004571
John McCall550e0c22009-10-21 00:40:46 +00004572 QualType Result = TL.getType();
4573 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004574 ElementType != T->getElementType() ||
4575 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004576 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004577 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004579 if (Result.isNull())
4580 return QualType();
4581 }
John McCall550e0c22009-10-21 00:40:46 +00004582
4583 // Result might be dependent or not.
4584 if (isa<DependentSizedExtVectorType>(Result)) {
4585 DependentSizedExtVectorTypeLoc NewTL
4586 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4587 NewTL.setNameLoc(TL.getNameLoc());
4588 } else {
4589 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4590 NewTL.setNameLoc(TL.getNameLoc());
4591 }
4592
4593 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004594}
Mike Stump11289f42009-09-09 15:08:12 +00004595
4596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004597QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004599 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600 QualType ElementType = getDerived().TransformType(T->getElementType());
4601 if (ElementType.isNull())
4602 return QualType();
4603
John McCall550e0c22009-10-21 00:40:46 +00004604 QualType Result = TL.getType();
4605 if (getDerived().AlwaysRebuild() ||
4606 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004607 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004608 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004609 if (Result.isNull())
4610 return QualType();
4611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004612
John McCall550e0c22009-10-21 00:40:46 +00004613 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4614 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004615
John McCall550e0c22009-10-21 00:40:46 +00004616 return Result;
4617}
4618
4619template<typename Derived>
4620QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004621 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004622 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004623 QualType ElementType = getDerived().TransformType(T->getElementType());
4624 if (ElementType.isNull())
4625 return QualType();
4626
4627 QualType Result = TL.getType();
4628 if (getDerived().AlwaysRebuild() ||
4629 ElementType != T->getElementType()) {
4630 Result = getDerived().RebuildExtVectorType(ElementType,
4631 T->getNumElements(),
4632 /*FIXME*/ SourceLocation());
4633 if (Result.isNull())
4634 return QualType();
4635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004636
John McCall550e0c22009-10-21 00:40:46 +00004637 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4638 NewTL.setNameLoc(TL.getNameLoc());
4639
4640 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004641}
Mike Stump11289f42009-09-09 15:08:12 +00004642
David Blaikie05785d12013-02-20 22:23:23 +00004643template <typename Derived>
4644ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4645 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4646 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004647 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004648 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004649
Douglas Gregor715e4612011-01-14 22:40:04 +00004650 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004651 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004652 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004653 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004654 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004655
Douglas Gregor715e4612011-01-14 22:40:04 +00004656 TypeLocBuilder TLB;
4657 TypeLoc NewTL = OldDI->getTypeLoc();
4658 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004659
4660 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004661 OldExpansionTL.getPatternLoc());
4662 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004663 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004664
4665 Result = RebuildPackExpansionType(Result,
4666 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004667 OldExpansionTL.getEllipsisLoc(),
4668 NumExpansions);
4669 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004670 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004671
Douglas Gregor715e4612011-01-14 22:40:04 +00004672 PackExpansionTypeLoc NewExpansionTL
4673 = TLB.push<PackExpansionTypeLoc>(Result);
4674 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4675 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4676 } else
4677 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004678 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004679 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004680
John McCall8fb0d9d2011-05-01 22:35:37 +00004681 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004682 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004683
4684 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4685 OldParm->getDeclContext(),
4686 OldParm->getInnerLocStart(),
4687 OldParm->getLocation(),
4688 OldParm->getIdentifier(),
4689 NewDI->getType(),
4690 NewDI,
4691 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004692 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004693 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4694 OldParm->getFunctionScopeIndex() + indexAdjustment);
4695 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004696}
4697
David Majnemer59f77922016-06-24 04:05:48 +00004698template <typename Derived>
4699bool TreeTransform<Derived>::TransformFunctionTypeParams(
4700 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4701 const QualType *ParamTypes,
4702 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4703 SmallVectorImpl<QualType> &OutParamTypes,
4704 SmallVectorImpl<ParmVarDecl *> *PVars,
4705 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004706 int indexAdjustment = 0;
4707
David Majnemer59f77922016-06-24 04:05:48 +00004708 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004709 for (unsigned i = 0; i != NumParams; ++i) {
4710 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004711 assert(OldParm->getFunctionScopeIndex() == i);
4712
David Blaikie05785d12013-02-20 22:23:23 +00004713 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004714 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004715 if (OldParm->isParameterPack()) {
4716 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004717 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004718
Douglas Gregor5499af42011-01-05 23:12:31 +00004719 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004720 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004721 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004722 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4723 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004724 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4725
Douglas Gregor5499af42011-01-05 23:12:31 +00004726 // Determine whether we should expand the parameter packs.
4727 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004728 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004729 Optional<unsigned> OrigNumExpansions =
4730 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004731 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004732 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4733 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004734 Unexpanded,
4735 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004736 RetainExpansion,
4737 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004738 return true;
4739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004740
Douglas Gregor5499af42011-01-05 23:12:31 +00004741 if (ShouldExpand) {
4742 // Expand the function parameter pack into multiple, separate
4743 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004744 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004745 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004746 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004747 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004748 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004749 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004750 OrigNumExpansions,
4751 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004752 if (!NewParm)
4753 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004754
John McCallc8e321d2016-03-01 02:09:25 +00004755 if (ParamInfos)
4756 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004757 OutParamTypes.push_back(NewParm->getType());
4758 if (PVars)
4759 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004760 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004761
4762 // If we're supposed to retain a pack expansion, do so by temporarily
4763 // forgetting the partially-substituted parameter pack.
4764 if (RetainExpansion) {
4765 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004766 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004767 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004768 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004769 OrigNumExpansions,
4770 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004771 if (!NewParm)
4772 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004773
John McCallc8e321d2016-03-01 02:09:25 +00004774 if (ParamInfos)
4775 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004776 OutParamTypes.push_back(NewParm->getType());
4777 if (PVars)
4778 PVars->push_back(NewParm);
4779 }
4780
John McCall8fb0d9d2011-05-01 22:35:37 +00004781 // The next parameter should have the same adjustment as the
4782 // last thing we pushed, but we post-incremented indexAdjustment
4783 // on every push. Also, if we push nothing, the adjustment should
4784 // go down by one.
4785 indexAdjustment--;
4786
Douglas Gregor5499af42011-01-05 23:12:31 +00004787 // We're done with the pack expansion.
4788 continue;
4789 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004790
4791 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004792 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4794 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004795 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004796 NumExpansions,
4797 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004798 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004799 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004800 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004801 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004802
John McCall58f10c32010-03-11 09:03:00 +00004803 if (!NewParm)
4804 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004805
John McCallc8e321d2016-03-01 02:09:25 +00004806 if (ParamInfos)
4807 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004808 OutParamTypes.push_back(NewParm->getType());
4809 if (PVars)
4810 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004811 continue;
4812 }
John McCall58f10c32010-03-11 09:03:00 +00004813
4814 // Deal with the possibility that we don't have a parameter
4815 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004816 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004817 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004818 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004819 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004820 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004821 = dyn_cast<PackExpansionType>(OldType)) {
4822 // We have a function parameter pack that may need to be expanded.
4823 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004824 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004825 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004826
Douglas Gregor5499af42011-01-05 23:12:31 +00004827 // Determine whether we should expand the parameter packs.
4828 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004829 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004830 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004831 Unexpanded,
4832 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004833 RetainExpansion,
4834 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004835 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
Douglas Gregor5499af42011-01-05 23:12:31 +00004838 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004839 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004840 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004841 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004842 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4843 QualType NewType = getDerived().TransformType(Pattern);
4844 if (NewType.isNull())
4845 return true;
John McCall58f10c32010-03-11 09:03:00 +00004846
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004847 if (NewType->containsUnexpandedParameterPack()) {
4848 NewType =
4849 getSema().getASTContext().getPackExpansionType(NewType, None);
4850
4851 if (NewType.isNull())
4852 return true;
4853 }
4854
John McCallc8e321d2016-03-01 02:09:25 +00004855 if (ParamInfos)
4856 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004857 OutParamTypes.push_back(NewType);
4858 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004859 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004861
Douglas Gregor5499af42011-01-05 23:12:31 +00004862 // We're done with the pack expansion.
4863 continue;
4864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
Douglas Gregor48d24112011-01-10 20:53:55 +00004866 // If we're supposed to retain a pack expansion, do so by temporarily
4867 // forgetting the partially-substituted parameter pack.
4868 if (RetainExpansion) {
4869 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4870 QualType NewType = getDerived().TransformType(Pattern);
4871 if (NewType.isNull())
4872 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004873
John McCallc8e321d2016-03-01 02:09:25 +00004874 if (ParamInfos)
4875 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004876 OutParamTypes.push_back(NewType);
4877 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004878 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004879 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004880
Chad Rosier1dcde962012-08-08 18:46:20 +00004881 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004882 // expansion.
4883 OldType = Expansion->getPattern();
4884 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004885 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4886 NewType = getDerived().TransformType(OldType);
4887 } else {
4888 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004890
Douglas Gregor5499af42011-01-05 23:12:31 +00004891 if (NewType.isNull())
4892 return true;
4893
4894 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004895 NewType = getSema().Context.getPackExpansionType(NewType,
4896 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004897
John McCallc8e321d2016-03-01 02:09:25 +00004898 if (ParamInfos)
4899 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004900 OutParamTypes.push_back(NewType);
4901 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004902 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004903 }
4904
John McCall8fb0d9d2011-05-01 22:35:37 +00004905#ifndef NDEBUG
4906 if (PVars) {
4907 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4908 if (ParmVarDecl *parm = (*PVars)[i])
4909 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004910 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004911#endif
4912
4913 return false;
4914}
John McCall58f10c32010-03-11 09:03:00 +00004915
4916template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004917QualType
John McCall550e0c22009-10-21 00:40:46 +00004918TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004919 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004920 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004921 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004922 return getDerived().TransformFunctionProtoType(
4923 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004924 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4925 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4926 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004927 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004928}
4929
Richard Smith2e321552014-11-12 02:00:47 +00004930template<typename Derived> template<typename Fn>
4931QualType TreeTransform<Derived>::TransformFunctionProtoType(
4932 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4933 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004934
Douglas Gregor4afc2362010-08-31 00:26:14 +00004935 // Transform the parameters and return type.
4936 //
Richard Smithf623c962012-04-17 00:58:00 +00004937 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004938 // When the function has a trailing return type, we instantiate the
4939 // parameters before the return type, since the return type can then refer
4940 // to the parameters themselves (via decltype, sizeof, etc.).
4941 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004942 SmallVector<QualType, 4> ParamTypes;
4943 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004944 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004945 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004946
Douglas Gregor7fb25412010-10-01 18:44:50 +00004947 QualType ResultType;
4948
Richard Smith1226c602012-08-14 22:51:13 +00004949 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004950 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004951 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004952 TL.getTypePtr()->param_type_begin(),
4953 T->getExtParameterInfosOrNull(),
4954 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004955 return QualType();
4956
Douglas Gregor3024f072012-04-16 07:05:22 +00004957 {
4958 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004959 // If a declaration declares a member function or member function
4960 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004961 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004962 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004963 // declarator.
4964 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
Alp Toker42a16a62014-01-25 23:51:36 +00004966 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004967 if (ResultType.isNull())
4968 return QualType();
4969 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004970 }
4971 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004972 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004973 if (ResultType.isNull())
4974 return QualType();
4975
Alp Toker9cacbab2014-01-20 20:26:09 +00004976 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004977 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004978 TL.getTypePtr()->param_type_begin(),
4979 T->getExtParameterInfosOrNull(),
4980 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004981 return QualType();
4982 }
4983
Richard Smith2e321552014-11-12 02:00:47 +00004984 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4985
4986 bool EPIChanged = false;
4987 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4988 return QualType();
4989
John McCallc8e321d2016-03-01 02:09:25 +00004990 // Handle extended parameter information.
4991 if (auto NewExtParamInfos =
4992 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4993 if (!EPI.ExtParameterInfos ||
4994 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4995 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4996 EPIChanged = true;
4997 }
4998 EPI.ExtParameterInfos = NewExtParamInfos;
4999 } else if (EPI.ExtParameterInfos) {
5000 EPIChanged = true;
5001 EPI.ExtParameterInfos = nullptr;
5002 }
Richard Smithf623c962012-04-17 00:58:00 +00005003
John McCall550e0c22009-10-21 00:40:46 +00005004 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005005 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005006 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005007 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005008 if (Result.isNull())
5009 return QualType();
5010 }
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCall550e0c22009-10-21 00:40:46 +00005012 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005013 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005014 NewTL.setLParenLoc(TL.getLParenLoc());
5015 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005016 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005017 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5018 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005019
5020 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregord6ff3322009-08-04 16:50:30 +00005023template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005024bool TreeTransform<Derived>::TransformExceptionSpec(
5025 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5026 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5027 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5028
5029 // Instantiate a dynamic noexcept expression, if any.
5030 if (ESI.Type == EST_ComputedNoexcept) {
5031 EnterExpressionEvaluationContext Unevaluated(getSema(),
5032 Sema::ConstantEvaluated);
5033 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5034 if (NoexceptExpr.isInvalid())
5035 return true;
5036
Richard Smith03a4aa32016-06-23 19:02:52 +00005037 // FIXME: This is bogus, a noexcept expression is not a condition.
5038 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005039 if (NoexceptExpr.isInvalid())
5040 return true;
5041
5042 if (!NoexceptExpr.get()->isValueDependent()) {
5043 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5044 NoexceptExpr.get(), nullptr,
5045 diag::err_noexcept_needs_constant_expression,
5046 /*AllowFold*/false);
5047 if (NoexceptExpr.isInvalid())
5048 return true;
5049 }
5050
5051 if (ESI.NoexceptExpr != NoexceptExpr.get())
5052 Changed = true;
5053 ESI.NoexceptExpr = NoexceptExpr.get();
5054 }
5055
5056 if (ESI.Type != EST_Dynamic)
5057 return false;
5058
5059 // Instantiate a dynamic exception specification's type.
5060 for (QualType T : ESI.Exceptions) {
5061 if (const PackExpansionType *PackExpansion =
5062 T->getAs<PackExpansionType>()) {
5063 Changed = true;
5064
5065 // We have a pack expansion. Instantiate it.
5066 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5067 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5068 Unexpanded);
5069 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5070
5071 // Determine whether the set of unexpanded parameter packs can and
5072 // should
5073 // be expanded.
5074 bool Expand = false;
5075 bool RetainExpansion = false;
5076 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5077 // FIXME: Track the location of the ellipsis (and track source location
5078 // information for the types in the exception specification in general).
5079 if (getDerived().TryExpandParameterPacks(
5080 Loc, SourceRange(), Unexpanded, Expand,
5081 RetainExpansion, NumExpansions))
5082 return true;
5083
5084 if (!Expand) {
5085 // We can't expand this pack expansion into separate arguments yet;
5086 // just substitute into the pattern and create a new pack expansion
5087 // type.
5088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5089 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5090 if (U.isNull())
5091 return true;
5092
5093 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5094 Exceptions.push_back(U);
5095 continue;
5096 }
5097
5098 // Substitute into the pack expansion pattern for each slice of the
5099 // pack.
5100 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5101 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5102
5103 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5104 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5105 return true;
5106
5107 Exceptions.push_back(U);
5108 }
5109 } else {
5110 QualType U = getDerived().TransformType(T);
5111 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5112 return true;
5113 if (T != U)
5114 Changed = true;
5115
5116 Exceptions.push_back(U);
5117 }
5118 }
5119
5120 ESI.Exceptions = Exceptions;
5121 return false;
5122}
5123
5124template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005125QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005126 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005127 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005128 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005129 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005130 if (ResultType.isNull())
5131 return QualType();
5132
5133 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005134 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005135 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5136
5137 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005138 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005139 NewTL.setLParenLoc(TL.getLParenLoc());
5140 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005141 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005142
5143 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005144}
Mike Stump11289f42009-09-09 15:08:12 +00005145
John McCallb96ec562009-12-04 22:46:56 +00005146template<typename Derived> QualType
5147TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005148 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005149 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005150 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005151 if (!D)
5152 return QualType();
5153
5154 QualType Result = TL.getType();
5155 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5156 Result = getDerived().RebuildUnresolvedUsingType(D);
5157 if (Result.isNull())
5158 return QualType();
5159 }
5160
5161 // We might get an arbitrary type spec type back. We should at
5162 // least always get a type spec type, though.
5163 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5164 NewTL.setNameLoc(TL.getNameLoc());
5165
5166 return Result;
5167}
5168
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005170QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005171 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005172 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005173 TypedefNameDecl *Typedef
5174 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5175 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005176 if (!Typedef)
5177 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005178
John McCall550e0c22009-10-21 00:40:46 +00005179 QualType Result = TL.getType();
5180 if (getDerived().AlwaysRebuild() ||
5181 Typedef != T->getDecl()) {
5182 Result = getDerived().RebuildTypedefType(Typedef);
5183 if (Result.isNull())
5184 return QualType();
5185 }
Mike Stump11289f42009-09-09 15:08:12 +00005186
John McCall550e0c22009-10-21 00:40:46 +00005187 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5188 NewTL.setNameLoc(TL.getNameLoc());
5189
5190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005191}
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregord6ff3322009-08-04 16:50:30 +00005193template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005194QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005195 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005196 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5198 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005199
John McCalldadc5752010-08-24 06:29:42 +00005200 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201 if (E.isInvalid())
5202 return QualType();
5203
Eli Friedmane4f22df2012-02-29 04:03:55 +00005204 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5205 if (E.isInvalid())
5206 return QualType();
5207
John McCall550e0c22009-10-21 00:40:46 +00005208 QualType Result = TL.getType();
5209 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005210 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005211 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005212 if (Result.isNull())
5213 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005215 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCall550e0c22009-10-21 00:40:46 +00005217 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005218 NewTL.setTypeofLoc(TL.getTypeofLoc());
5219 NewTL.setLParenLoc(TL.getLParenLoc());
5220 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005221
5222 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005223}
Mike Stump11289f42009-09-09 15:08:12 +00005224
5225template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005226QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005227 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005228 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5229 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5230 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005232
John McCall550e0c22009-10-21 00:40:46 +00005233 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005234 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5235 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005236 if (Result.isNull())
5237 return QualType();
5238 }
Mike Stump11289f42009-09-09 15:08:12 +00005239
John McCall550e0c22009-10-21 00:40:46 +00005240 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005241 NewTL.setTypeofLoc(TL.getTypeofLoc());
5242 NewTL.setLParenLoc(TL.getLParenLoc());
5243 NewTL.setRParenLoc(TL.getRParenLoc());
5244 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005245
5246 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247}
Mike Stump11289f42009-09-09 15:08:12 +00005248
5249template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005250QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005251 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005252 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005253
Douglas Gregore922c772009-08-04 22:27:00 +00005254 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005255 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5256 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005257
John McCalldadc5752010-08-24 06:29:42 +00005258 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259 if (E.isInvalid())
5260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005261
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005262 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005263 if (E.isInvalid())
5264 return QualType();
5265
John McCall550e0c22009-10-21 00:40:46 +00005266 QualType Result = TL.getType();
5267 if (getDerived().AlwaysRebuild() ||
5268 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005269 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005270 if (Result.isNull())
5271 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005272 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005273 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005274
John McCall550e0c22009-10-21 00:40:46 +00005275 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5276 NewTL.setNameLoc(TL.getNameLoc());
5277
5278 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005279}
5280
5281template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005282QualType TreeTransform<Derived>::TransformUnaryTransformType(
5283 TypeLocBuilder &TLB,
5284 UnaryTransformTypeLoc TL) {
5285 QualType Result = TL.getType();
5286 if (Result->isDependentType()) {
5287 const UnaryTransformType *T = TL.getTypePtr();
5288 QualType NewBase =
5289 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5290 Result = getDerived().RebuildUnaryTransformType(NewBase,
5291 T->getUTTKind(),
5292 TL.getKWLoc());
5293 if (Result.isNull())
5294 return QualType();
5295 }
5296
5297 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5298 NewTL.setKWLoc(TL.getKWLoc());
5299 NewTL.setParensRange(TL.getParensRange());
5300 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5301 return Result;
5302}
5303
5304template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005305QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5306 AutoTypeLoc TL) {
5307 const AutoType *T = TL.getTypePtr();
5308 QualType OldDeduced = T->getDeducedType();
5309 QualType NewDeduced;
5310 if (!OldDeduced.isNull()) {
5311 NewDeduced = getDerived().TransformType(OldDeduced);
5312 if (NewDeduced.isNull())
5313 return QualType();
5314 }
5315
5316 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005317 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5318 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005319 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005320 if (Result.isNull())
5321 return QualType();
5322 }
5323
5324 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5325 NewTL.setNameLoc(TL.getNameLoc());
5326
5327 return Result;
5328}
5329
5330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005332 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005333 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005334 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005335 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5336 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 if (!Record)
5338 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall550e0c22009-10-21 00:40:46 +00005340 QualType Result = TL.getType();
5341 if (getDerived().AlwaysRebuild() ||
5342 Record != T->getDecl()) {
5343 Result = getDerived().RebuildRecordType(Record);
5344 if (Result.isNull())
5345 return QualType();
5346 }
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall550e0c22009-10-21 00:40:46 +00005348 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5349 NewTL.setNameLoc(TL.getNameLoc());
5350
5351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005352}
Mike Stump11289f42009-09-09 15:08:12 +00005353
5354template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005355QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005356 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005357 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005358 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005359 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5360 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005361 if (!Enum)
5362 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005363
John McCall550e0c22009-10-21 00:40:46 +00005364 QualType Result = TL.getType();
5365 if (getDerived().AlwaysRebuild() ||
5366 Enum != T->getDecl()) {
5367 Result = getDerived().RebuildEnumType(Enum);
5368 if (Result.isNull())
5369 return QualType();
5370 }
Mike Stump11289f42009-09-09 15:08:12 +00005371
John McCall550e0c22009-10-21 00:40:46 +00005372 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5373 NewTL.setNameLoc(TL.getNameLoc());
5374
5375 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005376}
John McCallfcc33b02009-09-05 00:15:47 +00005377
John McCalle78aac42010-03-10 03:28:59 +00005378template<typename Derived>
5379QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5380 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005381 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005382 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5383 TL.getTypePtr()->getDecl());
5384 if (!D) return QualType();
5385
5386 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5387 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5388 return T;
5389}
5390
Douglas Gregord6ff3322009-08-04 16:50:30 +00005391template<typename Derived>
5392QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005393 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005394 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005395 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005396}
5397
Mike Stump11289f42009-09-09 15:08:12 +00005398template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005399QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005400 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005401 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005402 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005403
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005404 // Substitute into the replacement type, which itself might involve something
5405 // that needs to be transformed. This only tends to occur with default
5406 // template arguments of template template parameters.
5407 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5408 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5409 if (Replacement.isNull())
5410 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005412 // Always canonicalize the replacement type.
5413 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5414 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005415 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005416 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005417
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005418 // Propagate type-source information.
5419 SubstTemplateTypeParmTypeLoc NewTL
5420 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5421 NewTL.setNameLoc(TL.getNameLoc());
5422 return Result;
5423
John McCallcebee162009-10-18 09:09:24 +00005424}
5425
5426template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005427QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5428 TypeLocBuilder &TLB,
5429 SubstTemplateTypeParmPackTypeLoc TL) {
5430 return TransformTypeSpecType(TLB, TL);
5431}
5432
5433template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005434QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005435 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005436 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005437 const TemplateSpecializationType *T = TL.getTypePtr();
5438
Douglas Gregordf846d12011-03-02 18:46:51 +00005439 // The nested-name-specifier never matters in a TemplateSpecializationType,
5440 // because we can't have a dependent nested-name-specifier anyway.
5441 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005442 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005443 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5444 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005445 if (Template.isNull())
5446 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005447
John McCall31f82722010-11-12 08:19:04 +00005448 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5449}
5450
Eli Friedman0dfb8892011-10-06 23:00:33 +00005451template<typename Derived>
5452QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5453 AtomicTypeLoc TL) {
5454 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5455 if (ValueType.isNull())
5456 return QualType();
5457
5458 QualType Result = TL.getType();
5459 if (getDerived().AlwaysRebuild() ||
5460 ValueType != TL.getValueLoc().getType()) {
5461 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5462 if (Result.isNull())
5463 return QualType();
5464 }
5465
5466 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5467 NewTL.setKWLoc(TL.getKWLoc());
5468 NewTL.setLParenLoc(TL.getLParenLoc());
5469 NewTL.setRParenLoc(TL.getRParenLoc());
5470
5471 return Result;
5472}
5473
Xiuli Pan9c14e282016-01-09 12:53:17 +00005474template <typename Derived>
5475QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5476 PipeTypeLoc TL) {
5477 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5478 if (ValueType.isNull())
5479 return QualType();
5480
5481 QualType Result = TL.getType();
5482 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5483 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5484 if (Result.isNull())
5485 return QualType();
5486 }
5487
5488 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5489 NewTL.setKWLoc(TL.getKWLoc());
5490
5491 return Result;
5492}
5493
Chad Rosier1dcde962012-08-08 18:46:20 +00005494 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005495 /// container that provides a \c getArgLoc() member function.
5496 ///
5497 /// This iterator is intended to be used with the iterator form of
5498 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5499 template<typename ArgLocContainer>
5500 class TemplateArgumentLocContainerIterator {
5501 ArgLocContainer *Container;
5502 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005503
Douglas Gregorfe921a72010-12-20 23:36:19 +00005504 public:
5505 typedef TemplateArgumentLoc value_type;
5506 typedef TemplateArgumentLoc reference;
5507 typedef int difference_type;
5508 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005509
Douglas Gregorfe921a72010-12-20 23:36:19 +00005510 class pointer {
5511 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005512
Douglas Gregorfe921a72010-12-20 23:36:19 +00005513 public:
5514 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005515
Douglas Gregorfe921a72010-12-20 23:36:19 +00005516 const TemplateArgumentLoc *operator->() const {
5517 return &Arg;
5518 }
5519 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005520
5521
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005522 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005523
Douglas Gregorfe921a72010-12-20 23:36:19 +00005524 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5525 unsigned Index)
5526 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005527
Douglas Gregorfe921a72010-12-20 23:36:19 +00005528 TemplateArgumentLocContainerIterator &operator++() {
5529 ++Index;
5530 return *this;
5531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005532
Douglas Gregorfe921a72010-12-20 23:36:19 +00005533 TemplateArgumentLocContainerIterator operator++(int) {
5534 TemplateArgumentLocContainerIterator Old(*this);
5535 ++(*this);
5536 return Old;
5537 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005538
Douglas Gregorfe921a72010-12-20 23:36:19 +00005539 TemplateArgumentLoc operator*() const {
5540 return Container->getArgLoc(Index);
5541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregorfe921a72010-12-20 23:36:19 +00005543 pointer operator->() const {
5544 return pointer(Container->getArgLoc(Index));
5545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005546
Douglas Gregorfe921a72010-12-20 23:36:19 +00005547 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005548 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005549 return X.Container == Y.Container && X.Index == Y.Index;
5550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005551
Douglas Gregorfe921a72010-12-20 23:36:19 +00005552 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005553 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005554 return !(X == Y);
5555 }
5556 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005557
5558
John McCall31f82722010-11-12 08:19:04 +00005559template <typename Derived>
5560QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5561 TypeLocBuilder &TLB,
5562 TemplateSpecializationTypeLoc TL,
5563 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005564 TemplateArgumentListInfo NewTemplateArgs;
5565 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5566 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005567 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5568 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005569 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005570 ArgIterator(TL, TL.getNumArgs()),
5571 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005572 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005573
John McCall0ad16662009-10-29 08:12:44 +00005574 // FIXME: maybe don't rebuild if all the template arguments are the same.
5575
5576 QualType Result =
5577 getDerived().RebuildTemplateSpecializationType(Template,
5578 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005579 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005580
5581 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005582 // Specializations of template template parameters are represented as
5583 // TemplateSpecializationTypes, and substitution of type alias templates
5584 // within a dependent context can transform them into
5585 // DependentTemplateSpecializationTypes.
5586 if (isa<DependentTemplateSpecializationType>(Result)) {
5587 DependentTemplateSpecializationTypeLoc NewTL
5588 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005589 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005590 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005591 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005592 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005593 NewTL.setLAngleLoc(TL.getLAngleLoc());
5594 NewTL.setRAngleLoc(TL.getRAngleLoc());
5595 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5596 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5597 return Result;
5598 }
5599
John McCall0ad16662009-10-29 08:12:44 +00005600 TemplateSpecializationTypeLoc NewTL
5601 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005602 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005603 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5604 NewTL.setLAngleLoc(TL.getLAngleLoc());
5605 NewTL.setRAngleLoc(TL.getRAngleLoc());
5606 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5607 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005608 }
Mike Stump11289f42009-09-09 15:08:12 +00005609
John McCall0ad16662009-10-29 08:12:44 +00005610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005611}
Mike Stump11289f42009-09-09 15:08:12 +00005612
Douglas Gregor5a064722011-02-28 17:23:35 +00005613template <typename Derived>
5614QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5615 TypeLocBuilder &TLB,
5616 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005617 TemplateName Template,
5618 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005619 TemplateArgumentListInfo NewTemplateArgs;
5620 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5621 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5622 typedef TemplateArgumentLocContainerIterator<
5623 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005624 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005625 ArgIterator(TL, TL.getNumArgs()),
5626 NewTemplateArgs))
5627 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005628
Douglas Gregor5a064722011-02-28 17:23:35 +00005629 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005630
Douglas Gregor5a064722011-02-28 17:23:35 +00005631 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5632 QualType Result
5633 = getSema().Context.getDependentTemplateSpecializationType(
5634 TL.getTypePtr()->getKeyword(),
5635 DTN->getQualifier(),
5636 DTN->getIdentifier(),
5637 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005638
Douglas Gregor5a064722011-02-28 17:23:35 +00005639 DependentTemplateSpecializationTypeLoc NewTL
5640 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005641 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005642 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005643 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005644 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005645 NewTL.setLAngleLoc(TL.getLAngleLoc());
5646 NewTL.setRAngleLoc(TL.getRAngleLoc());
5647 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5648 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5649 return Result;
5650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005651
5652 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005653 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005654 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005655 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005656
Douglas Gregor5a064722011-02-28 17:23:35 +00005657 if (!Result.isNull()) {
5658 /// FIXME: Wrap this in an elaborated-type-specifier?
5659 TemplateSpecializationTypeLoc NewTL
5660 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005661 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005662 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005663 NewTL.setLAngleLoc(TL.getLAngleLoc());
5664 NewTL.setRAngleLoc(TL.getRAngleLoc());
5665 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5666 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005668
Douglas Gregor5a064722011-02-28 17:23:35 +00005669 return Result;
5670}
5671
Mike Stump11289f42009-09-09 15:08:12 +00005672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005673QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005674TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005675 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005676 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005677
Douglas Gregor844cb502011-03-01 18:12:44 +00005678 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005679 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005680 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005681 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005682 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5683 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005684 return QualType();
5685 }
Mike Stump11289f42009-09-09 15:08:12 +00005686
John McCall31f82722010-11-12 08:19:04 +00005687 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5688 if (NamedT.isNull())
5689 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005690
Richard Smith3f1b5d02011-05-05 21:57:07 +00005691 // C++0x [dcl.type.elab]p2:
5692 // If the identifier resolves to a typedef-name or the simple-template-id
5693 // resolves to an alias template specialization, the
5694 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005695 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5696 if (const TemplateSpecializationType *TST =
5697 NamedT->getAs<TemplateSpecializationType>()) {
5698 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005699 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5700 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005701 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5702 diag::err_tag_reference_non_tag) << 4;
5703 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5704 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005705 }
5706 }
5707
John McCall550e0c22009-10-21 00:40:46 +00005708 QualType Result = TL.getType();
5709 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005710 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005711 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005712 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005713 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005714 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005715 if (Result.isNull())
5716 return QualType();
5717 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005718
Abramo Bagnara6150c882010-05-11 21:36:43 +00005719 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005720 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005721 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005722 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005723}
Mike Stump11289f42009-09-09 15:08:12 +00005724
5725template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005726QualType TreeTransform<Derived>::TransformAttributedType(
5727 TypeLocBuilder &TLB,
5728 AttributedTypeLoc TL) {
5729 const AttributedType *oldType = TL.getTypePtr();
5730 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5731 if (modifiedType.isNull())
5732 return QualType();
5733
5734 QualType result = TL.getType();
5735
5736 // FIXME: dependent operand expressions?
5737 if (getDerived().AlwaysRebuild() ||
5738 modifiedType != oldType->getModifiedType()) {
5739 // TODO: this is really lame; we should really be rebuilding the
5740 // equivalent type from first principles.
5741 QualType equivalentType
5742 = getDerived().TransformType(oldType->getEquivalentType());
5743 if (equivalentType.isNull())
5744 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005745
5746 // Check whether we can add nullability; it is only represented as
5747 // type sugar, and therefore cannot be diagnosed in any other way.
5748 if (auto nullability = oldType->getImmediateNullability()) {
5749 if (!modifiedType->canHaveNullability()) {
5750 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005751 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005752 return QualType();
5753 }
5754 }
5755
John McCall81904512011-01-06 01:58:22 +00005756 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5757 modifiedType,
5758 equivalentType);
5759 }
5760
5761 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5762 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5763 if (TL.hasAttrOperand())
5764 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5765 if (TL.hasAttrExprOperand())
5766 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5767 else if (TL.hasAttrEnumOperand())
5768 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5769
5770 return result;
5771}
5772
5773template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005774QualType
5775TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5776 ParenTypeLoc TL) {
5777 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5778 if (Inner.isNull())
5779 return QualType();
5780
5781 QualType Result = TL.getType();
5782 if (getDerived().AlwaysRebuild() ||
5783 Inner != TL.getInnerLoc().getType()) {
5784 Result = getDerived().RebuildParenType(Inner);
5785 if (Result.isNull())
5786 return QualType();
5787 }
5788
5789 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5790 NewTL.setLParenLoc(TL.getLParenLoc());
5791 NewTL.setRParenLoc(TL.getRParenLoc());
5792 return Result;
5793}
5794
5795template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005796QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005797 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005798 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005799
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005800 NestedNameSpecifierLoc QualifierLoc
5801 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5802 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005803 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005804
John McCallc392f372010-06-11 00:33:02 +00005805 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005806 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005807 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005808 QualifierLoc,
5809 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005810 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005811 if (Result.isNull())
5812 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005813
Abramo Bagnarad7548482010-05-19 21:37:53 +00005814 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5815 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005816 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5817
Abramo Bagnarad7548482010-05-19 21:37:53 +00005818 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005819 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005820 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005821 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005822 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005823 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005824 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005825 NewTL.setNameLoc(TL.getNameLoc());
5826 }
John McCall550e0c22009-10-21 00:40:46 +00005827 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005828}
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregord6ff3322009-08-04 16:50:30 +00005830template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005831QualType TreeTransform<Derived>::
5832 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005833 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005834 NestedNameSpecifierLoc QualifierLoc;
5835 if (TL.getQualifierLoc()) {
5836 QualifierLoc
5837 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5838 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005839 return QualType();
5840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
John McCall31f82722010-11-12 08:19:04 +00005842 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005843 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005844}
5845
5846template<typename Derived>
5847QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005848TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5849 DependentTemplateSpecializationTypeLoc TL,
5850 NestedNameSpecifierLoc QualifierLoc) {
5851 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Douglas Gregora7a795b2011-03-01 20:11:18 +00005853 TemplateArgumentListInfo NewTemplateArgs;
5854 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5855 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005856
Douglas Gregora7a795b2011-03-01 20:11:18 +00005857 typedef TemplateArgumentLocContainerIterator<
5858 DependentTemplateSpecializationTypeLoc> ArgIterator;
5859 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5860 ArgIterator(TL, TL.getNumArgs()),
5861 NewTemplateArgs))
5862 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregora7a795b2011-03-01 20:11:18 +00005864 QualType Result
5865 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5866 QualifierLoc,
5867 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005868 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005869 NewTemplateArgs);
5870 if (Result.isNull())
5871 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005872
Douglas Gregora7a795b2011-03-01 20:11:18 +00005873 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5874 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005875
Douglas Gregora7a795b2011-03-01 20:11:18 +00005876 // Copy information relevant to the template specialization.
5877 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005878 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005879 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005880 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005881 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5882 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005883 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005884 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005885
Douglas Gregora7a795b2011-03-01 20:11:18 +00005886 // Copy information relevant to the elaborated type.
5887 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005888 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005889 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005890 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5891 DependentTemplateSpecializationTypeLoc SpecTL
5892 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005893 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005894 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005895 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005896 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005897 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5898 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005899 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005900 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005901 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005902 TemplateSpecializationTypeLoc SpecTL
5903 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005904 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005905 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005906 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5907 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005908 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005909 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005910 }
5911 return Result;
5912}
5913
5914template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005915QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5916 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005917 QualType Pattern
5918 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005919 if (Pattern.isNull())
5920 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005921
5922 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005923 if (getDerived().AlwaysRebuild() ||
5924 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005925 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005926 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005927 TL.getEllipsisLoc(),
5928 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005929 if (Result.isNull())
5930 return QualType();
5931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005932
Douglas Gregor822d0302011-01-12 17:07:58 +00005933 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5934 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5935 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005936}
5937
5938template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005939QualType
5940TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005941 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005942 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005943 TLB.pushFullCopy(TL);
5944 return TL.getType();
5945}
5946
5947template<typename Derived>
5948QualType
5949TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005950 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005951 // Transform base type.
5952 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5953 if (BaseType.isNull())
5954 return QualType();
5955
5956 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5957
5958 // Transform type arguments.
5959 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5960 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5961 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5962 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5963 QualType TypeArg = TypeArgInfo->getType();
5964 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5965 AnyChanged = true;
5966
5967 // We have a pack expansion. Instantiate it.
5968 const auto *PackExpansion = PackExpansionLoc.getType()
5969 ->castAs<PackExpansionType>();
5970 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5971 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5972 Unexpanded);
5973 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5974
5975 // Determine whether the set of unexpanded parameter packs can
5976 // and should be expanded.
5977 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5978 bool Expand = false;
5979 bool RetainExpansion = false;
5980 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5981 if (getDerived().TryExpandParameterPacks(
5982 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5983 Unexpanded, Expand, RetainExpansion, NumExpansions))
5984 return QualType();
5985
5986 if (!Expand) {
5987 // We can't expand this pack expansion into separate arguments yet;
5988 // just substitute into the pattern and create a new pack expansion
5989 // type.
5990 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5991
5992 TypeLocBuilder TypeArgBuilder;
5993 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5994 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5995 PatternLoc);
5996 if (NewPatternType.isNull())
5997 return QualType();
5998
5999 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6000 NewPatternType, NumExpansions);
6001 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6002 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6003 NewTypeArgInfos.push_back(
6004 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6005 continue;
6006 }
6007
6008 // Substitute into the pack expansion pattern for each slice of the
6009 // pack.
6010 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6011 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6012
6013 TypeLocBuilder TypeArgBuilder;
6014 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6015
6016 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6017 PatternLoc);
6018 if (NewTypeArg.isNull())
6019 return QualType();
6020
6021 NewTypeArgInfos.push_back(
6022 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6023 }
6024
6025 continue;
6026 }
6027
6028 TypeLocBuilder TypeArgBuilder;
6029 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6030 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6031 if (NewTypeArg.isNull())
6032 return QualType();
6033
6034 // If nothing changed, just keep the old TypeSourceInfo.
6035 if (NewTypeArg == TypeArg) {
6036 NewTypeArgInfos.push_back(TypeArgInfo);
6037 continue;
6038 }
6039
6040 NewTypeArgInfos.push_back(
6041 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6042 AnyChanged = true;
6043 }
6044
6045 QualType Result = TL.getType();
6046 if (getDerived().AlwaysRebuild() || AnyChanged) {
6047 // Rebuild the type.
6048 Result = getDerived().RebuildObjCObjectType(
6049 BaseType,
6050 TL.getLocStart(),
6051 TL.getTypeArgsLAngleLoc(),
6052 NewTypeArgInfos,
6053 TL.getTypeArgsRAngleLoc(),
6054 TL.getProtocolLAngleLoc(),
6055 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6056 TL.getNumProtocols()),
6057 TL.getProtocolLocs(),
6058 TL.getProtocolRAngleLoc());
6059
6060 if (Result.isNull())
6061 return QualType();
6062 }
6063
6064 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006065 NewT.setHasBaseTypeAsWritten(true);
6066 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6067 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6068 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6069 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6070 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6071 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6072 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6073 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6074 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006075}
Mike Stump11289f42009-09-09 15:08:12 +00006076
6077template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006078QualType
6079TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006080 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006081 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6082 if (PointeeType.isNull())
6083 return QualType();
6084
6085 QualType Result = TL.getType();
6086 if (getDerived().AlwaysRebuild() ||
6087 PointeeType != TL.getPointeeLoc().getType()) {
6088 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6089 TL.getStarLoc());
6090 if (Result.isNull())
6091 return QualType();
6092 }
6093
6094 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6095 NewT.setStarLoc(TL.getStarLoc());
6096 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006097}
6098
Douglas Gregord6ff3322009-08-04 16:50:30 +00006099//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006100// Statement transformation
6101//===----------------------------------------------------------------------===//
6102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006103StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006104TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006105 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006106}
6107
6108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006110TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6111 return getDerived().TransformCompoundStmt(S, false);
6112}
6113
6114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006115StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006116TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006117 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006118 Sema::CompoundScopeRAII CompoundScope(getSema());
6119
John McCall1ababa62010-08-27 19:56:05 +00006120 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006121 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006122 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006123 for (auto *B : S->body()) {
6124 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006125 if (Result.isInvalid()) {
6126 // Immediately fail if this was a DeclStmt, since it's very
6127 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006128 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006129 return StmtError();
6130
6131 // Otherwise, just keep processing substatements and fail later.
6132 SubStmtInvalid = true;
6133 continue;
6134 }
Mike Stump11289f42009-09-09 15:08:12 +00006135
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006136 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006137 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006138 }
Mike Stump11289f42009-09-09 15:08:12 +00006139
John McCall1ababa62010-08-27 19:56:05 +00006140 if (SubStmtInvalid)
6141 return StmtError();
6142
Douglas Gregorebe10102009-08-20 07:17:43 +00006143 if (!getDerived().AlwaysRebuild() &&
6144 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006145 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006146
6147 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006148 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 S->getRBracLoc(),
6150 IsStmtExpr);
6151}
Mike Stump11289f42009-09-09 15:08:12 +00006152
Douglas Gregorebe10102009-08-20 07:17:43 +00006153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006155TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006156 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006157 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006158 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6159 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006160
Eli Friedman06577382009-11-19 03:14:00 +00006161 // Transform the left-hand case value.
6162 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006163 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006164 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006165 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006166
Eli Friedman06577382009-11-19 03:14:00 +00006167 // Transform the right-hand case value (for the GNU case-range extension).
6168 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006169 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006170 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006172 }
Mike Stump11289f42009-09-09 15:08:12 +00006173
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 // Build the case statement.
6175 // Case statements are always rebuilt so that they will attached to their
6176 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006177 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006178 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006180 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 S->getColonLoc());
6182 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006186 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006191 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006192}
6193
6194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006195StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006196TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006197 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006198 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006199 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006200 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregorebe10102009-08-20 07:17:43 +00006202 // Default statements are always rebuilt
6203 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006204 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006205}
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregorebe10102009-08-20 07:17:43 +00006207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006208StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006209TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006210 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006211 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006213
Chris Lattnercab02a62011-02-17 20:34:02 +00006214 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6215 S->getDecl());
6216 if (!LD)
6217 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006218
6219
Douglas Gregorebe10102009-08-20 07:17:43 +00006220 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006221 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006222 cast<LabelDecl>(LD), SourceLocation(),
6223 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006224}
Mike Stump11289f42009-09-09 15:08:12 +00006225
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006226template <typename Derived>
6227const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6228 if (!R)
6229 return R;
6230
6231 switch (R->getKind()) {
6232// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6233#define ATTR(X)
6234#define PRAGMA_SPELLING_ATTR(X) \
6235 case attr::X: \
6236 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6237#include "clang/Basic/AttrList.inc"
6238 default:
6239 return R;
6240 }
6241}
6242
6243template <typename Derived>
6244StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6245 bool AttrsChanged = false;
6246 SmallVector<const Attr *, 1> Attrs;
6247
6248 // Visit attributes and keep track if any are transformed.
6249 for (const auto *I : S->getAttrs()) {
6250 const Attr *R = getDerived().TransformAttr(I);
6251 AttrsChanged |= (I != R);
6252 Attrs.push_back(R);
6253 }
6254
Richard Smithc202b282012-04-14 00:33:13 +00006255 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6256 if (SubStmt.isInvalid())
6257 return StmtError();
6258
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006259 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006260 return S;
6261
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006262 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006263 SubStmt.get());
6264}
6265
6266template<typename Derived>
6267StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006268TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006269 // Transform the initialization statement
6270 StmtResult Init = getDerived().TransformStmt(S->getInit());
6271 if (Init.isInvalid())
6272 return StmtError();
6273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006275 Sema::ConditionResult Cond = getDerived().TransformCondition(
6276 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006277 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6278 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006279 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Richard Smithb130fe72016-06-23 19:16:49 +00006282 // If this is a constexpr if, determine which arm we should instantiate.
6283 llvm::Optional<bool> ConstexprConditionValue;
6284 if (S->isConstexpr())
6285 ConstexprConditionValue = Cond.getKnownValue();
6286
Douglas Gregorebe10102009-08-20 07:17:43 +00006287 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006288 StmtResult Then;
6289 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6290 Then = getDerived().TransformStmt(S->getThen());
6291 if (Then.isInvalid())
6292 return StmtError();
6293 } else {
6294 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6295 }
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregorebe10102009-08-20 07:17:43 +00006297 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006298 StmtResult Else;
6299 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6300 Else = getDerived().TransformStmt(S->getElse());
6301 if (Else.isInvalid())
6302 return StmtError();
6303 }
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregorebe10102009-08-20 07:17:43 +00006305 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006306 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006307 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006308 Then.get() == S->getThen() &&
6309 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006310 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006311
Richard Smithb130fe72016-06-23 19:16:49 +00006312 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006313 Init.get(), Then.get(), S->getElseLoc(),
6314 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006315}
6316
6317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006318StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006319TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006320 // Transform the initialization statement
6321 StmtResult Init = getDerived().TransformStmt(S->getInit());
6322 if (Init.isInvalid())
6323 return StmtError();
6324
Douglas Gregorebe10102009-08-20 07:17:43 +00006325 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006326 Sema::ConditionResult Cond = getDerived().TransformCondition(
6327 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6328 Sema::ConditionKind::Switch);
6329 if (Cond.isInvalid())
6330 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006333 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006334 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6335 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006336 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006337 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregorebe10102009-08-20 07:17:43 +00006339 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006340 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006341 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006342 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006343
Douglas Gregorebe10102009-08-20 07:17:43 +00006344 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006345 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6346 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006347}
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregorebe10102009-08-20 07:17:43 +00006349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006350StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006351TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006352 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006353 Sema::ConditionResult Cond = getDerived().TransformCondition(
6354 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6355 Sema::ConditionKind::Boolean);
6356 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006358
Douglas Gregorebe10102009-08-20 07:17:43 +00006359 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006360 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006361 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006362 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregorebe10102009-08-20 07:17:43 +00006364 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006365 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006366 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006367 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006368
Richard Smith03a4aa32016-06-23 19:02:52 +00006369 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006370}
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006373StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006374TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006375 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006376 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006377 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006378 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006380 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006381 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006382 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006384
Douglas Gregorebe10102009-08-20 07:17:43 +00006385 if (!getDerived().AlwaysRebuild() &&
6386 Cond.get() == S->getCond() &&
6387 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006388 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006389
John McCallb268a282010-08-23 23:25:46 +00006390 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6391 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006392 S->getRParenLoc());
6393}
Mike Stump11289f42009-09-09 15:08:12 +00006394
Douglas Gregorebe10102009-08-20 07:17:43 +00006395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006396StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006397TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006398 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006399 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006400 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006403 // In OpenMP loop region loop control variable must be captured and be
6404 // private. Perform analysis of first part (if any).
6405 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6406 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006409 Sema::ConditionResult Cond = getDerived().TransformCondition(
6410 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6411 Sema::ConditionKind::Boolean);
6412 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006414
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006416 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006417 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006419
Richard Smith945f8d32013-01-14 22:39:08 +00006420 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006421 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006423
Douglas Gregorebe10102009-08-20 07:17:43 +00006424 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006425 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006426 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregorebe10102009-08-20 07:17:43 +00006429 if (!getDerived().AlwaysRebuild() &&
6430 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006431 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006432 Inc.get() == S->getInc() &&
6433 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006434 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregorebe10102009-08-20 07:17:43 +00006436 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006437 Init.get(), Cond, FullInc,
6438 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006439}
6440
6441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006443TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006444 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6445 S->getLabel());
6446 if (!LD)
6447 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006448
Douglas Gregorebe10102009-08-20 07:17:43 +00006449 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006450 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006451 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006452}
6453
6454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006455StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006456TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006457 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006458 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006459 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006460 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006461
Douglas Gregorebe10102009-08-20 07:17:43 +00006462 if (!getDerived().AlwaysRebuild() &&
6463 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006464 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006465
6466 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006467 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006468}
6469
6470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006471StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006472TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006473 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006474}
Mike Stump11289f42009-09-09 15:08:12 +00006475
Douglas Gregorebe10102009-08-20 07:17:43 +00006476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006478TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006479 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006480}
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregorebe10102009-08-20 07:17:43 +00006482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006483StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006484TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006485 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6486 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006487 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006488 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006489
Mike Stump11289f42009-09-09 15:08:12 +00006490 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006491 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006492 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006493}
Mike Stump11289f42009-09-09 15:08:12 +00006494
Douglas Gregorebe10102009-08-20 07:17:43 +00006495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006496StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006497TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006498 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006499 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006500 for (auto *D : S->decls()) {
6501 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006502 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006504
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006505 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006506 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregorebe10102009-08-20 07:17:43 +00006508 Decls.push_back(Transformed);
6509 }
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregorebe10102009-08-20 07:17:43 +00006511 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006512 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006513
Rafael Espindolaab417692013-07-09 12:05:01 +00006514 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregorebe10102009-08-20 07:17:43 +00006517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006519TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006520
Benjamin Kramerf0623432012-08-23 22:51:59 +00006521 SmallVector<Expr*, 8> Constraints;
6522 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006523 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006524
John McCalldadc5752010-08-24 06:29:42 +00006525 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006526 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006527
6528 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006529
Anders Carlssonaaeef072010-01-24 05:50:09 +00006530 // Go through the outputs.
6531 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006532 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006533
Anders Carlssonaaeef072010-01-24 05:50:09 +00006534 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006535 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006536
Anders Carlssonaaeef072010-01-24 05:50:09 +00006537 // Transform the output expr.
6538 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006539 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006540 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006541 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006542
Anders Carlssonaaeef072010-01-24 05:50:09 +00006543 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006544
John McCallb268a282010-08-23 23:25:46 +00006545 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006547
Anders Carlssonaaeef072010-01-24 05:50:09 +00006548 // Go through the inputs.
6549 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006550 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006551
Anders Carlssonaaeef072010-01-24 05:50:09 +00006552 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006553 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006554
Anders Carlssonaaeef072010-01-24 05:50:09 +00006555 // Transform the input expr.
6556 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006557 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006558 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006559 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006560
Anders Carlssonaaeef072010-01-24 05:50:09 +00006561 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006562
John McCallb268a282010-08-23 23:25:46 +00006563 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006565
Anders Carlssonaaeef072010-01-24 05:50:09 +00006566 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006567 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006568
6569 // Go through the clobbers.
6570 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006571 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006572
6573 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006574 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006575 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6576 S->isVolatile(), S->getNumOutputs(),
6577 S->getNumInputs(), Names.data(),
6578 Constraints, Exprs, AsmString.get(),
6579 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006580}
6581
Chad Rosier32503022012-06-11 20:47:18 +00006582template<typename Derived>
6583StmtResult
6584TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006585 ArrayRef<Token> AsmToks =
6586 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006587
John McCallf413f5e2013-05-03 00:10:13 +00006588 bool HadError = false, HadChange = false;
6589
6590 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6591 SmallVector<Expr*, 8> TransformedExprs;
6592 TransformedExprs.reserve(SrcExprs.size());
6593 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6594 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6595 if (!Result.isUsable()) {
6596 HadError = true;
6597 } else {
6598 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006599 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006600 }
6601 }
6602
6603 if (HadError) return StmtError();
6604 if (!HadChange && !getDerived().AlwaysRebuild())
6605 return Owned(S);
6606
Chad Rosierb6f46c12012-08-15 16:53:30 +00006607 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006608 AsmToks, S->getAsmString(),
6609 S->getNumOutputs(), S->getNumInputs(),
6610 S->getAllConstraints(), S->getClobbers(),
6611 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006612}
Douglas Gregorebe10102009-08-20 07:17:43 +00006613
Richard Smith9f690bd2015-10-27 06:02:45 +00006614// C++ Coroutines TS
6615
6616template<typename Derived>
6617StmtResult
6618TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6619 // The coroutine body should be re-formed by the caller if necessary.
6620 return getDerived().TransformStmt(S->getBody());
6621}
6622
6623template<typename Derived>
6624StmtResult
6625TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6626 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6627 /*NotCopyInit*/false);
6628 if (Result.isInvalid())
6629 return StmtError();
6630
6631 // Always rebuild; we don't know if this needs to be injected into a new
6632 // context or if the promise type has changed.
6633 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6634}
6635
6636template<typename Derived>
6637ExprResult
6638TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6639 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6640 /*NotCopyInit*/false);
6641 if (Result.isInvalid())
6642 return ExprError();
6643
6644 // Always rebuild; we don't know if this needs to be injected into a new
6645 // context or if the promise type has changed.
6646 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6647}
6648
6649template<typename Derived>
6650ExprResult
6651TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6652 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6653 /*NotCopyInit*/false);
6654 if (Result.isInvalid())
6655 return ExprError();
6656
6657 // Always rebuild; we don't know if this needs to be injected into a new
6658 // context or if the promise type has changed.
6659 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6660}
6661
6662// Objective-C Statements.
6663
Douglas Gregorebe10102009-08-20 07:17:43 +00006664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006666TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006667 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006668 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006669 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006671
Douglas Gregor96c79492010-04-23 22:50:49 +00006672 // Transform the @catch statements (if present).
6673 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006674 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006675 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006676 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006677 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006679 if (Catch.get() != S->getCatchStmt(I))
6680 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006681 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006683
Douglas Gregor306de2f2010-04-22 23:59:56 +00006684 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006685 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006686 if (S->getFinallyStmt()) {
6687 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6688 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006689 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006690 }
6691
6692 // If nothing changed, just retain this statement.
6693 if (!getDerived().AlwaysRebuild() &&
6694 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006695 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006696 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006697 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006698
Douglas Gregor306de2f2010-04-22 23:59:56 +00006699 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006700 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006701 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006702}
Mike Stump11289f42009-09-09 15:08:12 +00006703
Douglas Gregorebe10102009-08-20 07:17:43 +00006704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006706TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006707 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006708 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006709 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006710 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006711 if (FromVar->getTypeSourceInfo()) {
6712 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6713 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006714 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006716
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006717 QualType T;
6718 if (TSInfo)
6719 T = TSInfo->getType();
6720 else {
6721 T = getDerived().TransformType(FromVar->getType());
6722 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006723 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006726 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6727 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006730
John McCalldadc5752010-08-24 06:29:42 +00006731 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006732 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
6735 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006736 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006737 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006738}
Mike Stump11289f42009-09-09 15:08:12 +00006739
Douglas Gregorebe10102009-08-20 07:17:43 +00006740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006741StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006742TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006743 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006744 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006745 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006746 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006747
Douglas Gregor306de2f2010-04-22 23:59:56 +00006748 // If nothing changed, just retain this statement.
6749 if (!getDerived().AlwaysRebuild() &&
6750 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006751 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006752
6753 // Build a new statement.
6754 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006755 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006756}
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregorebe10102009-08-20 07:17:43 +00006758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006759StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006760TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006761 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006762 if (S->getThrowExpr()) {
6763 Operand = getDerived().TransformExpr(S->getThrowExpr());
6764 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006765 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006767
Douglas Gregor2900c162010-04-22 21:44:01 +00006768 if (!getDerived().AlwaysRebuild() &&
6769 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006770 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006771
John McCallb268a282010-08-23 23:25:46 +00006772 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006773}
Mike Stump11289f42009-09-09 15:08:12 +00006774
Douglas Gregorebe10102009-08-20 07:17:43 +00006775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006776StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006777TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006778 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006779 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006780 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006781 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006783 Object =
6784 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6785 Object.get());
6786 if (Object.isInvalid())
6787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregor6148de72010-04-22 22:01:21 +00006789 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006790 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006791 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006793
Douglas Gregor6148de72010-04-22 22:01:21 +00006794 // If nothing change, just retain the current statement.
6795 if (!getDerived().AlwaysRebuild() &&
6796 Object.get() == S->getSynchExpr() &&
6797 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006798 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006799
6800 // Build a new statement.
6801 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006802 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006803}
6804
6805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006806StmtResult
John McCall31168b02011-06-15 23:02:42 +00006807TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6808 ObjCAutoreleasePoolStmt *S) {
6809 // Transform the body.
6810 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6811 if (Body.isInvalid())
6812 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006813
John McCall31168b02011-06-15 23:02:42 +00006814 // If nothing changed, just retain this statement.
6815 if (!getDerived().AlwaysRebuild() &&
6816 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006817 return S;
John McCall31168b02011-06-15 23:02:42 +00006818
6819 // Build a new statement.
6820 return getDerived().RebuildObjCAutoreleasePoolStmt(
6821 S->getAtLoc(), Body.get());
6822}
6823
6824template<typename Derived>
6825StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006826TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006827 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006828 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006829 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006830 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006831 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006832
Douglas Gregorf68a5082010-04-22 23:10:45 +00006833 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006834 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006835 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006836 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006837
Douglas Gregorf68a5082010-04-22 23:10:45 +00006838 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006839 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006840 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006842
Douglas Gregorf68a5082010-04-22 23:10:45 +00006843 // If nothing changed, just retain this statement.
6844 if (!getDerived().AlwaysRebuild() &&
6845 Element.get() == S->getElement() &&
6846 Collection.get() == S->getCollection() &&
6847 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006848 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006849
Douglas Gregorf68a5082010-04-22 23:10:45 +00006850 // Build a new statement.
6851 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006852 Element.get(),
6853 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006854 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006855 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006856}
6857
David Majnemer5f7efef2013-10-15 09:50:08 +00006858template <typename Derived>
6859StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006861 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006862 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6863 TypeSourceInfo *T =
6864 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006865 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006866 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006867
David Majnemer5f7efef2013-10-15 09:50:08 +00006868 Var = getDerived().RebuildExceptionDecl(
6869 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6870 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006871 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006872 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006873 }
Mike Stump11289f42009-09-09 15:08:12 +00006874
Douglas Gregorebe10102009-08-20 07:17:43 +00006875 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006876 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006877 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006878 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006879
David Majnemer5f7efef2013-10-15 09:50:08 +00006880 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006881 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006882 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006883
David Majnemer5f7efef2013-10-15 09:50:08 +00006884 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006885}
Mike Stump11289f42009-09-09 15:08:12 +00006886
David Majnemer5f7efef2013-10-15 09:50:08 +00006887template <typename Derived>
6888StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006889 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006890 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006891 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006893
Douglas Gregorebe10102009-08-20 07:17:43 +00006894 // Transform the handlers.
6895 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006896 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006897 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006898 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006899 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006901
Douglas Gregorebe10102009-08-20 07:17:43 +00006902 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006903 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006904 }
Mike Stump11289f42009-09-09 15:08:12 +00006905
David Majnemer5f7efef2013-10-15 09:50:08 +00006906 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006907 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006908 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006909
John McCallb268a282010-08-23 23:25:46 +00006910 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006911 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006912}
Mike Stump11289f42009-09-09 15:08:12 +00006913
Richard Smith02e85f32011-04-14 22:09:26 +00006914template<typename Derived>
6915StmtResult
6916TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6917 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6918 if (Range.isInvalid())
6919 return StmtError();
6920
Richard Smith01694c32016-03-20 10:33:40 +00006921 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6922 if (Begin.isInvalid())
6923 return StmtError();
6924 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6925 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006926 return StmtError();
6927
6928 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6929 if (Cond.isInvalid())
6930 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006931 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006932 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006933 if (Cond.isInvalid())
6934 return StmtError();
6935 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006936 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006937
6938 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6939 if (Inc.isInvalid())
6940 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006941 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006942 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006943
6944 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6945 if (LoopVar.isInvalid())
6946 return StmtError();
6947
6948 StmtResult NewStmt = S;
6949 if (getDerived().AlwaysRebuild() ||
6950 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006951 Begin.get() != S->getBeginStmt() ||
6952 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006953 Cond.get() != S->getCond() ||
6954 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006955 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006956 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006957 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006958 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006959 Begin.get(), End.get(),
6960 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006961 Inc.get(), LoopVar.get(),
6962 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006963 if (NewStmt.isInvalid())
6964 return StmtError();
6965 }
Richard Smith02e85f32011-04-14 22:09:26 +00006966
6967 StmtResult Body = getDerived().TransformStmt(S->getBody());
6968 if (Body.isInvalid())
6969 return StmtError();
6970
6971 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6972 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006973 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006974 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006975 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006976 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006977 Begin.get(), End.get(),
6978 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006979 Inc.get(), LoopVar.get(),
6980 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006981 if (NewStmt.isInvalid())
6982 return StmtError();
6983 }
Richard Smith02e85f32011-04-14 22:09:26 +00006984
6985 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006986 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006987
6988 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6989}
6990
John Wiegley1c0675e2011-04-28 01:08:34 +00006991template<typename Derived>
6992StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006993TreeTransform<Derived>::TransformMSDependentExistsStmt(
6994 MSDependentExistsStmt *S) {
6995 // Transform the nested-name-specifier, if any.
6996 NestedNameSpecifierLoc QualifierLoc;
6997 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006998 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006999 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7000 if (!QualifierLoc)
7001 return StmtError();
7002 }
7003
7004 // Transform the declaration name.
7005 DeclarationNameInfo NameInfo = S->getNameInfo();
7006 if (NameInfo.getName()) {
7007 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7008 if (!NameInfo.getName())
7009 return StmtError();
7010 }
7011
7012 // Check whether anything changed.
7013 if (!getDerived().AlwaysRebuild() &&
7014 QualifierLoc == S->getQualifierLoc() &&
7015 NameInfo.getName() == S->getNameInfo().getName())
7016 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007017
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007018 // Determine whether this name exists, if we can.
7019 CXXScopeSpec SS;
7020 SS.Adopt(QualifierLoc);
7021 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007022 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007023 case Sema::IER_Exists:
7024 if (S->isIfExists())
7025 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007026
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007027 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7028
7029 case Sema::IER_DoesNotExist:
7030 if (S->isIfNotExists())
7031 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007032
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007033 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007034
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007035 case Sema::IER_Dependent:
7036 Dependent = true;
7037 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007038
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007039 case Sema::IER_Error:
7040 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007042
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007043 // We need to continue with the instantiation, so do so now.
7044 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7045 if (SubStmt.isInvalid())
7046 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007047
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007048 // If we have resolved the name, just transform to the substatement.
7049 if (!Dependent)
7050 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007051
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007052 // The name is still dependent, so build a dependent expression again.
7053 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7054 S->isIfExists(),
7055 QualifierLoc,
7056 NameInfo,
7057 SubStmt.get());
7058}
7059
7060template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007061ExprResult
7062TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7063 NestedNameSpecifierLoc QualifierLoc;
7064 if (E->getQualifierLoc()) {
7065 QualifierLoc
7066 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7067 if (!QualifierLoc)
7068 return ExprError();
7069 }
7070
7071 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7072 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7073 if (!PD)
7074 return ExprError();
7075
7076 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7077 if (Base.isInvalid())
7078 return ExprError();
7079
7080 return new (SemaRef.getASTContext())
7081 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7082 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7083 QualifierLoc, E->getMemberLoc());
7084}
7085
David Majnemerfad8f482013-10-15 09:33:02 +00007086template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007087ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7088 MSPropertySubscriptExpr *E) {
7089 auto BaseRes = getDerived().TransformExpr(E->getBase());
7090 if (BaseRes.isInvalid())
7091 return ExprError();
7092 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7093 if (IdxRes.isInvalid())
7094 return ExprError();
7095
7096 if (!getDerived().AlwaysRebuild() &&
7097 BaseRes.get() == E->getBase() &&
7098 IdxRes.get() == E->getIdx())
7099 return E;
7100
7101 return getDerived().RebuildArraySubscriptExpr(
7102 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7103}
7104
7105template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007106StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007107 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007108 if (TryBlock.isInvalid())
7109 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007110
7111 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007112 if (Handler.isInvalid())
7113 return StmtError();
7114
David Majnemerfad8f482013-10-15 09:33:02 +00007115 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7116 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007117 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007118
Warren Huntf6be4cb2014-07-25 20:52:51 +00007119 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7120 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007121}
7122
David Majnemerfad8f482013-10-15 09:33:02 +00007123template <typename Derived>
7124StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007125 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007126 if (Block.isInvalid())
7127 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007128
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007129 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007130}
7131
David Majnemerfad8f482013-10-15 09:33:02 +00007132template <typename Derived>
7133StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007134 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007135 if (FilterExpr.isInvalid())
7136 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007137
David Majnemer7e755502013-10-15 09:30:14 +00007138 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007139 if (Block.isInvalid())
7140 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007141
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007142 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7143 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007144}
7145
David Majnemerfad8f482013-10-15 09:33:02 +00007146template <typename Derived>
7147StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7148 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007149 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7150 else
7151 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7152}
7153
Nico Weber9b982072014-07-07 00:12:30 +00007154template<typename Derived>
7155StmtResult
7156TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7157 return S;
7158}
7159
Alexander Musman64d33f12014-06-04 07:53:32 +00007160//===----------------------------------------------------------------------===//
7161// OpenMP directive transformation
7162//===----------------------------------------------------------------------===//
7163template <typename Derived>
7164StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7165 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007166
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007167 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007168 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007169 ArrayRef<OMPClause *> Clauses = D->clauses();
7170 TClauses.reserve(Clauses.size());
7171 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7172 I != E; ++I) {
7173 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007174 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007175 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007176 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007177 if (Clause)
7178 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007179 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007180 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007181 }
7182 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007183 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007184 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007185 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7186 /*CurScope=*/nullptr);
7187 StmtResult Body;
7188 {
7189 Sema::CompoundScopeRAII CompoundScope(getSema());
7190 Body = getDerived().TransformStmt(
7191 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7192 }
7193 AssociatedStmt =
7194 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007195 if (AssociatedStmt.isInvalid()) {
7196 return StmtError();
7197 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007198 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007199 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007200 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007201 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007202
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007203 // Transform directive name for 'omp critical' directive.
7204 DeclarationNameInfo DirName;
7205 if (D->getDirectiveKind() == OMPD_critical) {
7206 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7207 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7208 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007209 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7210 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7211 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007212 } else if (D->getDirectiveKind() == OMPD_cancel) {
7213 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007214 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007215
Alexander Musman64d33f12014-06-04 07:53:32 +00007216 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007217 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7218 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007219}
7220
Alexander Musman64d33f12014-06-04 07:53:32 +00007221template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007222StmtResult
7223TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7224 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007225 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7226 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007227 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7228 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7229 return Res;
7230}
7231
Alexander Musman64d33f12014-06-04 07:53:32 +00007232template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007233StmtResult
7234TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7235 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007236 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7237 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007238 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7239 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007240 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007241}
7242
Alexey Bataevf29276e2014-06-18 04:14:57 +00007243template <typename Derived>
7244StmtResult
7245TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7246 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007247 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7248 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007249 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7250 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7251 return Res;
7252}
7253
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007254template <typename Derived>
7255StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007256TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7257 DeclarationNameInfo DirName;
7258 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7259 D->getLocStart());
7260 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7261 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7262 return Res;
7263}
7264
7265template <typename Derived>
7266StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007267TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7268 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007269 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7270 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007271 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7272 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7273 return Res;
7274}
7275
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007276template <typename Derived>
7277StmtResult
7278TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7279 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007280 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7281 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007282 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7283 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7284 return Res;
7285}
7286
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007287template <typename Derived>
7288StmtResult
7289TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7290 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007291 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7292 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007293 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7294 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7295 return Res;
7296}
7297
Alexey Bataev4acb8592014-07-07 13:01:15 +00007298template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007299StmtResult
7300TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7301 DeclarationNameInfo DirName;
7302 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7303 D->getLocStart());
7304 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7305 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7306 return Res;
7307}
7308
7309template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007310StmtResult
7311TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7312 getDerived().getSema().StartOpenMPDSABlock(
7313 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7314 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7315 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7316 return Res;
7317}
7318
7319template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007320StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7321 OMPParallelForDirective *D) {
7322 DeclarationNameInfo DirName;
7323 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7324 nullptr, D->getLocStart());
7325 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7326 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7327 return Res;
7328}
7329
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007330template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007331StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7332 OMPParallelForSimdDirective *D) {
7333 DeclarationNameInfo DirName;
7334 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7335 nullptr, D->getLocStart());
7336 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7337 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7338 return Res;
7339}
7340
7341template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007342StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7343 OMPParallelSectionsDirective *D) {
7344 DeclarationNameInfo DirName;
7345 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7346 nullptr, D->getLocStart());
7347 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7348 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7349 return Res;
7350}
7351
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007352template <typename Derived>
7353StmtResult
7354TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7355 DeclarationNameInfo DirName;
7356 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7357 D->getLocStart());
7358 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7359 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7360 return Res;
7361}
7362
Alexey Bataev68446b72014-07-18 07:47:19 +00007363template <typename Derived>
7364StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7365 OMPTaskyieldDirective *D) {
7366 DeclarationNameInfo DirName;
7367 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7368 D->getLocStart());
7369 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7370 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7371 return Res;
7372}
7373
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007374template <typename Derived>
7375StmtResult
7376TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7377 DeclarationNameInfo DirName;
7378 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7379 D->getLocStart());
7380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7381 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7382 return Res;
7383}
7384
Alexey Bataev2df347a2014-07-18 10:17:07 +00007385template <typename Derived>
7386StmtResult
7387TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7388 DeclarationNameInfo DirName;
7389 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7390 D->getLocStart());
7391 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7392 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7393 return Res;
7394}
7395
Alexey Bataev6125da92014-07-21 11:26:11 +00007396template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007397StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7398 OMPTaskgroupDirective *D) {
7399 DeclarationNameInfo DirName;
7400 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7401 D->getLocStart());
7402 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7403 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7404 return Res;
7405}
7406
7407template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007408StmtResult
7409TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7410 DeclarationNameInfo DirName;
7411 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7412 D->getLocStart());
7413 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7414 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7415 return Res;
7416}
7417
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007418template <typename Derived>
7419StmtResult
7420TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7421 DeclarationNameInfo DirName;
7422 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7423 D->getLocStart());
7424 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7425 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7426 return Res;
7427}
7428
Alexey Bataev0162e452014-07-22 10:10:35 +00007429template <typename Derived>
7430StmtResult
7431TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7432 DeclarationNameInfo DirName;
7433 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7434 D->getLocStart());
7435 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7436 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7437 return Res;
7438}
7439
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007440template <typename Derived>
7441StmtResult
7442TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7443 DeclarationNameInfo DirName;
7444 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7445 D->getLocStart());
7446 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7447 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7448 return Res;
7449}
7450
Alexey Bataev13314bf2014-10-09 04:18:56 +00007451template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007452StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7453 OMPTargetDataDirective *D) {
7454 DeclarationNameInfo DirName;
7455 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7456 D->getLocStart());
7457 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7458 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7459 return Res;
7460}
7461
7462template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007463StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7464 OMPTargetEnterDataDirective *D) {
7465 DeclarationNameInfo DirName;
7466 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7467 nullptr, D->getLocStart());
7468 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7469 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7470 return Res;
7471}
7472
7473template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007474StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7475 OMPTargetExitDataDirective *D) {
7476 DeclarationNameInfo DirName;
7477 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7478 nullptr, D->getLocStart());
7479 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7480 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7481 return Res;
7482}
7483
7484template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007485StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7486 OMPTargetParallelDirective *D) {
7487 DeclarationNameInfo DirName;
7488 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7489 nullptr, D->getLocStart());
7490 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7491 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7492 return Res;
7493}
7494
7495template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007496StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7497 OMPTargetParallelForDirective *D) {
7498 DeclarationNameInfo DirName;
7499 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7500 nullptr, D->getLocStart());
7501 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7502 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7503 return Res;
7504}
7505
7506template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007507StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7508 OMPTargetUpdateDirective *D) {
7509 DeclarationNameInfo DirName;
7510 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7511 nullptr, D->getLocStart());
7512 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7513 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7514 return Res;
7515}
7516
7517template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007518StmtResult
7519TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7520 DeclarationNameInfo DirName;
7521 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7522 D->getLocStart());
7523 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7524 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7525 return Res;
7526}
7527
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007528template <typename Derived>
7529StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7530 OMPCancellationPointDirective *D) {
7531 DeclarationNameInfo DirName;
7532 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7533 nullptr, D->getLocStart());
7534 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7535 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7536 return Res;
7537}
7538
Alexey Bataev80909872015-07-02 11:25:17 +00007539template <typename Derived>
7540StmtResult
7541TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7542 DeclarationNameInfo DirName;
7543 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7544 D->getLocStart());
7545 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7546 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7547 return Res;
7548}
7549
Alexey Bataev49f6e782015-12-01 04:18:41 +00007550template <typename Derived>
7551StmtResult
7552TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7553 DeclarationNameInfo DirName;
7554 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7555 D->getLocStart());
7556 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7557 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7558 return Res;
7559}
7560
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007561template <typename Derived>
7562StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7563 OMPTaskLoopSimdDirective *D) {
7564 DeclarationNameInfo DirName;
7565 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7566 nullptr, D->getLocStart());
7567 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7568 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7569 return Res;
7570}
7571
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007572template <typename Derived>
7573StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7574 OMPDistributeDirective *D) {
7575 DeclarationNameInfo DirName;
7576 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7577 D->getLocStart());
7578 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7579 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7580 return Res;
7581}
7582
Carlo Bertolli9925f152016-06-27 14:55:37 +00007583template <typename Derived>
7584StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7585 OMPDistributeParallelForDirective *D) {
7586 DeclarationNameInfo DirName;
7587 getDerived().getSema().StartOpenMPDSABlock(
7588 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7589 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7590 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7591 return Res;
7592}
7593
Kelvin Li4a39add2016-07-05 05:00:15 +00007594template <typename Derived>
7595StmtResult
7596TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7597 OMPDistributeParallelForSimdDirective *D) {
7598 DeclarationNameInfo DirName;
7599 getDerived().getSema().StartOpenMPDSABlock(
7600 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7601 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7602 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7603 return Res;
7604}
7605
Kelvin Li787f3fc2016-07-06 04:45:38 +00007606template <typename Derived>
7607StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7608 OMPDistributeSimdDirective *D) {
7609 DeclarationNameInfo DirName;
7610 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7611 nullptr, D->getLocStart());
7612 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7613 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7614 return Res;
7615}
7616
Kelvin Lia579b912016-07-14 02:54:56 +00007617template <typename Derived>
7618StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7619 OMPTargetParallelForSimdDirective *D) {
7620 DeclarationNameInfo DirName;
7621 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7622 DirName, nullptr,
7623 D->getLocStart());
7624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7626 return Res;
7627}
7628
Alexander Musman64d33f12014-06-04 07:53:32 +00007629//===----------------------------------------------------------------------===//
7630// OpenMP clause transformation
7631//===----------------------------------------------------------------------===//
7632template <typename Derived>
7633OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007634 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7635 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007636 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007637 return getDerived().RebuildOMPIfClause(
7638 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7639 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007640}
7641
Alexander Musman64d33f12014-06-04 07:53:32 +00007642template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007643OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7644 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7645 if (Cond.isInvalid())
7646 return nullptr;
7647 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7648 C->getLParenLoc(), C->getLocEnd());
7649}
7650
7651template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007652OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007653TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7654 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7655 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007656 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007657 return getDerived().RebuildOMPNumThreadsClause(
7658 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007659}
7660
Alexey Bataev62c87d22014-03-21 04:51:18 +00007661template <typename Derived>
7662OMPClause *
7663TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7664 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7665 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007666 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007667 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007668 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007669}
7670
Alexander Musman8bd31e62014-05-27 15:12:19 +00007671template <typename Derived>
7672OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007673TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7674 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7675 if (E.isInvalid())
7676 return nullptr;
7677 return getDerived().RebuildOMPSimdlenClause(
7678 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7679}
7680
7681template <typename Derived>
7682OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007683TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7684 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7685 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007686 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007687 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007688 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007689}
7690
Alexander Musman64d33f12014-06-04 07:53:32 +00007691template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007692OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007693TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007694 return getDerived().RebuildOMPDefaultClause(
7695 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7696 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007697}
7698
Alexander Musman64d33f12014-06-04 07:53:32 +00007699template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007700OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007701TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007702 return getDerived().RebuildOMPProcBindClause(
7703 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7704 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007705}
7706
Alexander Musman64d33f12014-06-04 07:53:32 +00007707template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007708OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007709TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7710 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7711 if (E.isInvalid())
7712 return nullptr;
7713 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007714 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007715 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007716 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007717 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7718}
7719
7720template <typename Derived>
7721OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007722TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007723 ExprResult E;
7724 if (auto *Num = C->getNumForLoops()) {
7725 E = getDerived().TransformExpr(Num);
7726 if (E.isInvalid())
7727 return nullptr;
7728 }
7729 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7730 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007731}
7732
7733template <typename Derived>
7734OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007735TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7736 // No need to rebuild this clause, no template-dependent parameters.
7737 return C;
7738}
7739
7740template <typename Derived>
7741OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007742TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7743 // No need to rebuild this clause, no template-dependent parameters.
7744 return C;
7745}
7746
7747template <typename Derived>
7748OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007749TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7750 // No need to rebuild this clause, no template-dependent parameters.
7751 return C;
7752}
7753
7754template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007755OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7756 // No need to rebuild this clause, no template-dependent parameters.
7757 return C;
7758}
7759
7760template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007761OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7762 // No need to rebuild this clause, no template-dependent parameters.
7763 return C;
7764}
7765
7766template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007767OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007768TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7769 // No need to rebuild this clause, no template-dependent parameters.
7770 return C;
7771}
7772
7773template <typename Derived>
7774OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007775TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7776 // No need to rebuild this clause, no template-dependent parameters.
7777 return C;
7778}
7779
7780template <typename Derived>
7781OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007782TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7783 // No need to rebuild this clause, no template-dependent parameters.
7784 return C;
7785}
7786
7787template <typename Derived>
7788OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007789TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7790 // No need to rebuild this clause, no template-dependent parameters.
7791 return C;
7792}
7793
7794template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007795OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7796 // No need to rebuild this clause, no template-dependent parameters.
7797 return C;
7798}
7799
7800template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007801OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007802TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7803 // No need to rebuild this clause, no template-dependent parameters.
7804 return C;
7805}
7806
7807template <typename Derived>
7808OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007809TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007810 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007811 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007812 for (auto *VE : C->varlists()) {
7813 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007814 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007815 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007816 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007817 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007818 return getDerived().RebuildOMPPrivateClause(
7819 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007820}
7821
Alexander Musman64d33f12014-06-04 07:53:32 +00007822template <typename Derived>
7823OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7824 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007825 llvm::SmallVector<Expr *, 16> Vars;
7826 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007827 for (auto *VE : C->varlists()) {
7828 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007829 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007830 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007831 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007832 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007833 return getDerived().RebuildOMPFirstprivateClause(
7834 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007835}
7836
Alexander Musman64d33f12014-06-04 07:53:32 +00007837template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007838OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007839TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7840 llvm::SmallVector<Expr *, 16> Vars;
7841 Vars.reserve(C->varlist_size());
7842 for (auto *VE : C->varlists()) {
7843 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7844 if (EVar.isInvalid())
7845 return nullptr;
7846 Vars.push_back(EVar.get());
7847 }
7848 return getDerived().RebuildOMPLastprivateClause(
7849 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7850}
7851
7852template <typename Derived>
7853OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007854TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7855 llvm::SmallVector<Expr *, 16> Vars;
7856 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007857 for (auto *VE : C->varlists()) {
7858 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007859 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007860 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007861 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007862 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007863 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7864 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007865}
7866
Alexander Musman64d33f12014-06-04 07:53:32 +00007867template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007868OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007869TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *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 CXXScopeSpec ReductionIdScopeSpec;
7879 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7880
7881 DeclarationNameInfo NameInfo = C->getNameInfo();
7882 if (NameInfo.getName()) {
7883 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7884 if (!NameInfo.getName())
7885 return nullptr;
7886 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007887 // Build a list of all UDR decls with the same names ranged by the Scopes.
7888 // The Scope boundary is a duplication of the previous decl.
7889 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7890 for (auto *E : C->reduction_ops()) {
7891 // Transform all the decls.
7892 if (E) {
7893 auto *ULE = cast<UnresolvedLookupExpr>(E);
7894 UnresolvedSet<8> Decls;
7895 for (auto *D : ULE->decls()) {
7896 NamedDecl *InstD =
7897 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7898 Decls.addDecl(InstD, InstD->getAccess());
7899 }
7900 UnresolvedReductions.push_back(
7901 UnresolvedLookupExpr::Create(
7902 SemaRef.Context, /*NamingClass=*/nullptr,
7903 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7904 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7905 Decls.begin(), Decls.end()));
7906 } else
7907 UnresolvedReductions.push_back(nullptr);
7908 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007909 return getDerived().RebuildOMPReductionClause(
7910 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007911 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007912}
7913
7914template <typename Derived>
7915OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007916TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7917 llvm::SmallVector<Expr *, 16> Vars;
7918 Vars.reserve(C->varlist_size());
7919 for (auto *VE : C->varlists()) {
7920 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7921 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007922 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007923 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007924 }
7925 ExprResult Step = getDerived().TransformExpr(C->getStep());
7926 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007927 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007928 return getDerived().RebuildOMPLinearClause(
7929 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7930 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007931}
7932
Alexander Musman64d33f12014-06-04 07:53:32 +00007933template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007934OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007935TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7936 llvm::SmallVector<Expr *, 16> Vars;
7937 Vars.reserve(C->varlist_size());
7938 for (auto *VE : C->varlists()) {
7939 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7940 if (EVar.isInvalid())
7941 return nullptr;
7942 Vars.push_back(EVar.get());
7943 }
7944 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7945 if (Alignment.isInvalid())
7946 return nullptr;
7947 return getDerived().RebuildOMPAlignedClause(
7948 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7949 C->getColonLoc(), C->getLocEnd());
7950}
7951
Alexander Musman64d33f12014-06-04 07:53:32 +00007952template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007953OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007954TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7955 llvm::SmallVector<Expr *, 16> Vars;
7956 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007957 for (auto *VE : C->varlists()) {
7958 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007959 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007960 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007961 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007962 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007963 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7964 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007965}
7966
Alexey Bataevbae9a792014-06-27 10:37:06 +00007967template <typename Derived>
7968OMPClause *
7969TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7970 llvm::SmallVector<Expr *, 16> Vars;
7971 Vars.reserve(C->varlist_size());
7972 for (auto *VE : C->varlists()) {
7973 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7974 if (EVar.isInvalid())
7975 return nullptr;
7976 Vars.push_back(EVar.get());
7977 }
7978 return getDerived().RebuildOMPCopyprivateClause(
7979 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7980}
7981
Alexey Bataev6125da92014-07-21 11:26:11 +00007982template <typename Derived>
7983OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7984 llvm::SmallVector<Expr *, 16> Vars;
7985 Vars.reserve(C->varlist_size());
7986 for (auto *VE : C->varlists()) {
7987 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7988 if (EVar.isInvalid())
7989 return nullptr;
7990 Vars.push_back(EVar.get());
7991 }
7992 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7993 C->getLParenLoc(), C->getLocEnd());
7994}
7995
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007996template <typename Derived>
7997OMPClause *
7998TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7999 llvm::SmallVector<Expr *, 16> Vars;
8000 Vars.reserve(C->varlist_size());
8001 for (auto *VE : C->varlists()) {
8002 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8003 if (EVar.isInvalid())
8004 return nullptr;
8005 Vars.push_back(EVar.get());
8006 }
8007 return getDerived().RebuildOMPDependClause(
8008 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8009 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8010}
8011
Michael Wonge710d542015-08-07 16:16:36 +00008012template <typename Derived>
8013OMPClause *
8014TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8015 ExprResult E = getDerived().TransformExpr(C->getDevice());
8016 if (E.isInvalid())
8017 return nullptr;
8018 return getDerived().RebuildOMPDeviceClause(
8019 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8020}
8021
Kelvin Li0bff7af2015-11-23 05:32:03 +00008022template <typename Derived>
8023OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8024 llvm::SmallVector<Expr *, 16> Vars;
8025 Vars.reserve(C->varlist_size());
8026 for (auto *VE : C->varlists()) {
8027 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8028 if (EVar.isInvalid())
8029 return nullptr;
8030 Vars.push_back(EVar.get());
8031 }
8032 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008033 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8034 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8035 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008036}
8037
Kelvin Li099bb8c2015-11-24 20:50:12 +00008038template <typename Derived>
8039OMPClause *
8040TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8041 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8042 if (E.isInvalid())
8043 return nullptr;
8044 return getDerived().RebuildOMPNumTeamsClause(
8045 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8046}
8047
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008048template <typename Derived>
8049OMPClause *
8050TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8051 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8052 if (E.isInvalid())
8053 return nullptr;
8054 return getDerived().RebuildOMPThreadLimitClause(
8055 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8056}
8057
Alexey Bataeva0569352015-12-01 10:17:31 +00008058template <typename Derived>
8059OMPClause *
8060TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8061 ExprResult E = getDerived().TransformExpr(C->getPriority());
8062 if (E.isInvalid())
8063 return nullptr;
8064 return getDerived().RebuildOMPPriorityClause(
8065 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8066}
8067
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008068template <typename Derived>
8069OMPClause *
8070TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8071 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8072 if (E.isInvalid())
8073 return nullptr;
8074 return getDerived().RebuildOMPGrainsizeClause(
8075 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8076}
8077
Alexey Bataev382967a2015-12-08 12:06:20 +00008078template <typename Derived>
8079OMPClause *
8080TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8081 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8082 if (E.isInvalid())
8083 return nullptr;
8084 return getDerived().RebuildOMPNumTasksClause(
8085 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8086}
8087
Alexey Bataev28c75412015-12-15 08:19:24 +00008088template <typename Derived>
8089OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8090 ExprResult E = getDerived().TransformExpr(C->getHint());
8091 if (E.isInvalid())
8092 return nullptr;
8093 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8094 C->getLParenLoc(), C->getLocEnd());
8095}
8096
Carlo Bertollib4adf552016-01-15 18:50:31 +00008097template <typename Derived>
8098OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8099 OMPDistScheduleClause *C) {
8100 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8101 if (E.isInvalid())
8102 return nullptr;
8103 return getDerived().RebuildOMPDistScheduleClause(
8104 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8105 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8106}
8107
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008108template <typename Derived>
8109OMPClause *
8110TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8111 return C;
8112}
8113
Samuel Antao661c0902016-05-26 17:39:58 +00008114template <typename Derived>
8115OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8116 llvm::SmallVector<Expr *, 16> Vars;
8117 Vars.reserve(C->varlist_size());
8118 for (auto *VE : C->varlists()) {
8119 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8120 if (EVar.isInvalid())
8121 return 0;
8122 Vars.push_back(EVar.get());
8123 }
8124 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8125 C->getLParenLoc(), C->getLocEnd());
8126}
8127
Samuel Antaoec172c62016-05-26 17:49:04 +00008128template <typename Derived>
8129OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8130 llvm::SmallVector<Expr *, 16> Vars;
8131 Vars.reserve(C->varlist_size());
8132 for (auto *VE : C->varlists()) {
8133 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8134 if (EVar.isInvalid())
8135 return 0;
8136 Vars.push_back(EVar.get());
8137 }
8138 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8139 C->getLParenLoc(), C->getLocEnd());
8140}
8141
Carlo Bertolli2404b172016-07-13 15:37:16 +00008142template <typename Derived>
8143OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8144 OMPUseDevicePtrClause *C) {
8145 llvm::SmallVector<Expr *, 16> Vars;
8146 Vars.reserve(C->varlist_size());
8147 for (auto *VE : C->varlists()) {
8148 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8149 if (EVar.isInvalid())
8150 return nullptr;
8151 Vars.push_back(EVar.get());
8152 }
8153 return getDerived().RebuildOMPUseDevicePtrClause(
8154 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8155}
8156
Carlo Bertolli70594e92016-07-13 17:16:49 +00008157template <typename Derived>
8158OMPClause *
8159TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8160 llvm::SmallVector<Expr *, 16> Vars;
8161 Vars.reserve(C->varlist_size());
8162 for (auto *VE : C->varlists()) {
8163 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8164 if (EVar.isInvalid())
8165 return nullptr;
8166 Vars.push_back(EVar.get());
8167 }
8168 return getDerived().RebuildOMPIsDevicePtrClause(
8169 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8170}
8171
Douglas Gregorebe10102009-08-20 07:17:43 +00008172//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008173// Expression transformation
8174//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008177TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008178 if (!E->isTypeDependent())
8179 return E;
8180
8181 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8182 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008183}
Mike Stump11289f42009-09-09 15:08:12 +00008184
8185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008187TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008188 NestedNameSpecifierLoc QualifierLoc;
8189 if (E->getQualifierLoc()) {
8190 QualifierLoc
8191 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8192 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008193 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008194 }
John McCallce546572009-12-08 09:08:17 +00008195
8196 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008197 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8198 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008199 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008201
John McCall815039a2010-08-17 21:27:17 +00008202 DeclarationNameInfo NameInfo = E->getNameInfo();
8203 if (NameInfo.getName()) {
8204 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8205 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008206 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008207 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008208
8209 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008210 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008211 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008212 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008213 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008214
8215 // Mark it referenced in the new context regardless.
8216 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008217 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008218
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008219 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008220 }
John McCallce546572009-12-08 09:08:17 +00008221
Craig Topperc3ec1492014-05-26 06:22:03 +00008222 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008223 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008224 TemplateArgs = &TransArgs;
8225 TransArgs.setLAngleLoc(E->getLAngleLoc());
8226 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008227 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8228 E->getNumTemplateArgs(),
8229 TransArgs))
8230 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008231 }
8232
Chad Rosier1dcde962012-08-08 18:46:20 +00008233 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008234 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008235}
Mike Stump11289f42009-09-09 15:08:12 +00008236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008239TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008240 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008241}
Mike Stump11289f42009-09-09 15:08:12 +00008242
Douglas Gregora16548e2009-08-11 05:31:07 +00008243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008245TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008246 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008247}
Mike Stump11289f42009-09-09 15:08:12 +00008248
Douglas Gregora16548e2009-08-11 05:31:07 +00008249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008251TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008252 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008257TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008258 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008259}
Mike Stump11289f42009-09-09 15:08:12 +00008260
Douglas Gregora16548e2009-08-11 05:31:07 +00008261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008263TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008264 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008265}
8266
8267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008268ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008269TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008270 if (FunctionDecl *FD = E->getDirectCallee())
8271 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008272 return SemaRef.MaybeBindToTemporary(E);
8273}
8274
8275template<typename Derived>
8276ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008277TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8278 ExprResult ControllingExpr =
8279 getDerived().TransformExpr(E->getControllingExpr());
8280 if (ControllingExpr.isInvalid())
8281 return ExprError();
8282
Chris Lattner01cf8db2011-07-20 06:58:45 +00008283 SmallVector<Expr *, 4> AssocExprs;
8284 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008285 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8286 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8287 if (TS) {
8288 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8289 if (!AssocType)
8290 return ExprError();
8291 AssocTypes.push_back(AssocType);
8292 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008293 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008294 }
8295
8296 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8297 if (AssocExpr.isInvalid())
8298 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008299 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008300 }
8301
8302 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8303 E->getDefaultLoc(),
8304 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008305 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008306 AssocTypes,
8307 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008308}
8309
8310template<typename Derived>
8311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008312TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008313 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008314 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008316
Douglas Gregora16548e2009-08-11 05:31:07 +00008317 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008318 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008319
John McCallb268a282010-08-23 23:25:46 +00008320 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008321 E->getRParen());
8322}
8323
Richard Smithdb2630f2012-10-21 03:28:35 +00008324/// \brief The operand of a unary address-of operator has special rules: it's
8325/// allowed to refer to a non-static member of a class even if there's no 'this'
8326/// object available.
8327template<typename Derived>
8328ExprResult
8329TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8330 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008331 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008332 else
8333 return getDerived().TransformExpr(E);
8334}
8335
Mike Stump11289f42009-09-09 15:08:12 +00008336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008337ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008338TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008339 ExprResult SubExpr;
8340 if (E->getOpcode() == UO_AddrOf)
8341 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8342 else
8343 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008344 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008346
Douglas Gregora16548e2009-08-11 05:31:07 +00008347 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008348 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8351 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008352 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008353}
Mike Stump11289f42009-09-09 15:08:12 +00008354
Douglas Gregora16548e2009-08-11 05:31:07 +00008355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008356ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008357TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8358 // Transform the type.
8359 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8360 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008361 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008362
Douglas Gregor882211c2010-04-28 22:16:22 +00008363 // Transform all of the components into components similar to what the
8364 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008365 // FIXME: It would be slightly more efficient in the non-dependent case to
8366 // just map FieldDecls, rather than requiring the rebuilder to look for
8367 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008368 // template code that we don't care.
8369 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008370 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008371 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008372 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008373 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008374 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008375 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008376 Comp.LocStart = ON.getSourceRange().getBegin();
8377 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008378 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008379 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008380 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008381 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008382 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008383 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008384
Douglas Gregor882211c2010-04-28 22:16:22 +00008385 ExprChanged = ExprChanged || Index.get() != FromIndex;
8386 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008387 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008388 break;
8389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008390
James Y Knight7281c352015-12-29 22:31:18 +00008391 case OffsetOfNode::Field:
8392 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008393 Comp.isBrackets = false;
8394 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008395 if (!Comp.U.IdentInfo)
8396 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008397
Douglas Gregor882211c2010-04-28 22:16:22 +00008398 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008399
James Y Knight7281c352015-12-29 22:31:18 +00008400 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008401 // Will be recomputed during the rebuild.
8402 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008404
Douglas Gregor882211c2010-04-28 22:16:22 +00008405 Components.push_back(Comp);
8406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008407
Douglas Gregor882211c2010-04-28 22:16:22 +00008408 // If nothing changed, retain the existing expression.
8409 if (!getDerived().AlwaysRebuild() &&
8410 Type == E->getTypeSourceInfo() &&
8411 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008412 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008413
Douglas Gregor882211c2010-04-28 22:16:22 +00008414 // Build a new offsetof expression.
8415 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008416 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008417}
8418
8419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008420ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008421TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008422 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008423 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008424 return E;
John McCall8d69a212010-11-15 23:31:06 +00008425}
8426
8427template<typename Derived>
8428ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008429TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8430 return E;
8431}
8432
8433template<typename Derived>
8434ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008435TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008436 // Rebuild the syntactic form. The original syntactic form has
8437 // opaque-value expressions in it, so strip those away and rebuild
8438 // the result. This is a really awful way of doing this, but the
8439 // better solution (rebuilding the semantic expressions and
8440 // rebinding OVEs as necessary) doesn't work; we'd need
8441 // TreeTransform to not strip away implicit conversions.
8442 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8443 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008444 if (result.isInvalid()) return ExprError();
8445
8446 // If that gives us a pseudo-object result back, the pseudo-object
8447 // expression must have been an lvalue-to-rvalue conversion which we
8448 // should reapply.
8449 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008450 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008451
8452 return result;
8453}
8454
8455template<typename Derived>
8456ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008457TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8458 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008459 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008460 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008461
John McCallbcd03502009-12-07 02:54:59 +00008462 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008463 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008465
John McCall4c98fd82009-11-04 07:28:41 +00008466 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008467 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008468
Peter Collingbournee190dee2011-03-11 19:24:49 +00008469 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8470 E->getKind(),
8471 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008472 }
Mike Stump11289f42009-09-09 15:08:12 +00008473
Eli Friedmane4f22df2012-02-29 04:03:55 +00008474 // C++0x [expr.sizeof]p1:
8475 // The operand is either an expression, which is an unevaluated operand
8476 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008477 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8478 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008479
Reid Kleckner32506ed2014-06-12 23:03:48 +00008480 // Try to recover if we have something like sizeof(T::X) where X is a type.
8481 // Notably, there must be *exactly* one set of parens if X is a type.
8482 TypeSourceInfo *RecoveryTSI = nullptr;
8483 ExprResult SubExpr;
8484 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8485 if (auto *DRE =
8486 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8487 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8488 PE, DRE, false, &RecoveryTSI);
8489 else
8490 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8491
8492 if (RecoveryTSI) {
8493 return getDerived().RebuildUnaryExprOrTypeTrait(
8494 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8495 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008497
Eli Friedmane4f22df2012-02-29 04:03:55 +00008498 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008499 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008500
Peter Collingbournee190dee2011-03-11 19:24:49 +00008501 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8502 E->getOperatorLoc(),
8503 E->getKind(),
8504 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008505}
Mike Stump11289f42009-09-09 15:08:12 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008509TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008510 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008513
John McCalldadc5752010-08-24 06:29:42 +00008514 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008517
8518
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 if (!getDerived().AlwaysRebuild() &&
8520 LHS.get() == E->getLHS() &&
8521 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008522 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008523
John McCallb268a282010-08-23 23:25:46 +00008524 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008525 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008526 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008527 E->getRBracketLoc());
8528}
Mike Stump11289f42009-09-09 15:08:12 +00008529
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008530template <typename Derived>
8531ExprResult
8532TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8533 ExprResult Base = getDerived().TransformExpr(E->getBase());
8534 if (Base.isInvalid())
8535 return ExprError();
8536
8537 ExprResult LowerBound;
8538 if (E->getLowerBound()) {
8539 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8540 if (LowerBound.isInvalid())
8541 return ExprError();
8542 }
8543
8544 ExprResult Length;
8545 if (E->getLength()) {
8546 Length = getDerived().TransformExpr(E->getLength());
8547 if (Length.isInvalid())
8548 return ExprError();
8549 }
8550
8551 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8552 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8553 return E;
8554
8555 return getDerived().RebuildOMPArraySectionExpr(
8556 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8557 Length.get(), E->getRBracketLoc());
8558}
8559
Mike Stump11289f42009-09-09 15:08:12 +00008560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008562TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008564 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008565 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008567
8568 // Transform arguments.
8569 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008570 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008571 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008572 &ArgChanged))
8573 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008574
Douglas Gregora16548e2009-08-11 05:31:07 +00008575 if (!getDerived().AlwaysRebuild() &&
8576 Callee.get() == E->getCallee() &&
8577 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008578 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008579
Douglas Gregora16548e2009-08-11 05:31:07 +00008580 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008581 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008582 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008583 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008584 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008585 E->getRParenLoc());
8586}
Mike Stump11289f42009-09-09 15:08:12 +00008587
8588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008590TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008591 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008592 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008593 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008594
Douglas Gregorea972d32011-02-28 21:54:11 +00008595 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008596 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008597 QualifierLoc
8598 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008599
Douglas Gregorea972d32011-02-28 21:54:11 +00008600 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008601 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008602 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008603 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008604
Eli Friedman2cfcef62009-12-04 06:40:45 +00008605 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008606 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8607 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008608 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008610
John McCall16df1e52010-03-30 21:47:33 +00008611 NamedDecl *FoundDecl = E->getFoundDecl();
8612 if (FoundDecl == E->getMemberDecl()) {
8613 FoundDecl = Member;
8614 } else {
8615 FoundDecl = cast_or_null<NamedDecl>(
8616 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8617 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008618 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008619 }
8620
Douglas Gregora16548e2009-08-11 05:31:07 +00008621 if (!getDerived().AlwaysRebuild() &&
8622 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008623 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008624 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008625 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008626 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008627
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008628 // Mark it referenced in the new context regardless.
8629 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008630 SemaRef.MarkMemberReferenced(E);
8631
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008632 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008633 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008634
John McCall6b51f282009-11-23 01:53:49 +00008635 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008636 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008637 TransArgs.setLAngleLoc(E->getLAngleLoc());
8638 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008639 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8640 E->getNumTemplateArgs(),
8641 TransArgs))
8642 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008644
Douglas Gregora16548e2009-08-11 05:31:07 +00008645 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008646 SourceLocation FakeOperatorLoc =
8647 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008648
John McCall38836f02010-01-15 08:34:02 +00008649 // FIXME: to do this check properly, we will need to preserve the
8650 // first-qualifier-in-scope here, just in case we had a dependent
8651 // base (and therefore couldn't do the check) and a
8652 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008653 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008654
John McCallb268a282010-08-23 23:25:46 +00008655 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008657 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008658 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008659 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008660 Member,
John McCall16df1e52010-03-30 21:47:33 +00008661 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008662 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008663 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008664 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008665}
Mike Stump11289f42009-09-09 15:08:12 +00008666
Douglas Gregora16548e2009-08-11 05:31:07 +00008667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008669TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008670 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008671 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008673
John McCalldadc5752010-08-24 06:29:42 +00008674 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008677
Douglas Gregora16548e2009-08-11 05:31:07 +00008678 if (!getDerived().AlwaysRebuild() &&
8679 LHS.get() == E->getLHS() &&
8680 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008681 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008682
Lang Hames5de91cc2012-10-02 04:45:10 +00008683 Sema::FPContractStateRAII FPContractState(getSema());
8684 getSema().FPFeatures.fp_contract = E->isFPContractable();
8685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008687 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008688}
8689
Mike Stump11289f42009-09-09 15:08:12 +00008690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008691ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008692TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008693 CompoundAssignOperator *E) {
8694 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008695}
Mike Stump11289f42009-09-09 15:08:12 +00008696
Douglas Gregora16548e2009-08-11 05:31:07 +00008697template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008698ExprResult TreeTransform<Derived>::
8699TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8700 // Just rebuild the common and RHS expressions and see whether we
8701 // get any changes.
8702
8703 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8704 if (commonExpr.isInvalid())
8705 return ExprError();
8706
8707 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8708 if (rhs.isInvalid())
8709 return ExprError();
8710
8711 if (!getDerived().AlwaysRebuild() &&
8712 commonExpr.get() == e->getCommon() &&
8713 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008714 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008715
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008716 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008717 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008718 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008719 e->getColonLoc(),
8720 rhs.get());
8721}
8722
8723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008725TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008726 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008727 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008729
John McCalldadc5752010-08-24 06:29:42 +00008730 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008731 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008733
John McCalldadc5752010-08-24 06:29:42 +00008734 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008735 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008737
Douglas Gregora16548e2009-08-11 05:31:07 +00008738 if (!getDerived().AlwaysRebuild() &&
8739 Cond.get() == E->getCond() &&
8740 LHS.get() == E->getLHS() &&
8741 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008742 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008743
John McCallb268a282010-08-23 23:25:46 +00008744 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008745 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008746 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008747 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008748 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008749}
Mike Stump11289f42009-09-09 15:08:12 +00008750
8751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008753TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008754 // Implicit casts are eliminated during transformation, since they
8755 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008756 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008757}
Mike Stump11289f42009-09-09 15:08:12 +00008758
Douglas Gregora16548e2009-08-11 05:31:07 +00008759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008761TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008762 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8763 if (!Type)
8764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008765
John McCalldadc5752010-08-24 06:29:42 +00008766 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008767 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008768 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008770
Douglas Gregora16548e2009-08-11 05:31:07 +00008771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008772 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008774 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008775
John McCall97513962010-01-15 18:39:57 +00008776 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008777 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008778 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008779 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008780}
Mike Stump11289f42009-09-09 15:08:12 +00008781
Douglas Gregora16548e2009-08-11 05:31:07 +00008782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008784TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008785 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8786 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8787 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008789
John McCalldadc5752010-08-24 06:29:42 +00008790 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008791 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008793
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008795 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008796 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008797 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008798
John McCall5d7aa7f2010-01-19 22:33:45 +00008799 // Note: the expression type doesn't necessarily match the
8800 // type-as-written, but that's okay, because it should always be
8801 // derivable from the initializer.
8802
John McCalle15bbff2010-01-18 19:35:47 +00008803 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008804 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008805 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008806}
Mike Stump11289f42009-09-09 15:08:12 +00008807
Douglas Gregora16548e2009-08-11 05:31:07 +00008808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008810TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008811 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008814
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 if (!getDerived().AlwaysRebuild() &&
8816 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008817 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008818
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008820 SourceLocation FakeOperatorLoc =
8821 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008822 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008823 E->getAccessorLoc(),
8824 E->getAccessor());
8825}
Mike Stump11289f42009-09-09 15:08:12 +00008826
Douglas Gregora16548e2009-08-11 05:31:07 +00008827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008829TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008830 if (InitListExpr *Syntactic = E->getSyntacticForm())
8831 E = Syntactic;
8832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008834
Benjamin Kramerf0623432012-08-23 22:51:59 +00008835 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008836 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008837 Inits, &InitChanged))
8838 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008839
Richard Smith520449d2015-02-05 06:15:50 +00008840 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8841 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8842 // in some cases. We can't reuse it in general, because the syntactic and
8843 // semantic forms are linked, and we can't know that semantic form will
8844 // match even if the syntactic form does.
8845 }
Mike Stump11289f42009-09-09 15:08:12 +00008846
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008847 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008848 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008849}
Mike Stump11289f42009-09-09 15:08:12 +00008850
Douglas Gregora16548e2009-08-11 05:31:07 +00008851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008853TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008854 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008855
Douglas Gregorebe10102009-08-20 07:17:43 +00008856 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008857 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008858 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008860
Douglas Gregorebe10102009-08-20 07:17:43 +00008861 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008862 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008863 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008864 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8865 if (D.isFieldDesignator()) {
8866 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8867 D.getDotLoc(),
8868 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 continue;
8870 }
Mike Stump11289f42009-09-09 15:08:12 +00008871
David Majnemerf7e36092016-06-23 00:15:04 +00008872 if (D.isArrayDesignator()) {
8873 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008874 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008876
David Majnemerf7e36092016-06-23 00:15:04 +00008877 Desig.AddDesignator(
8878 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008879
David Majnemerf7e36092016-06-23 00:15:04 +00008880 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008881 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008882 continue;
8883 }
Mike Stump11289f42009-09-09 15:08:12 +00008884
David Majnemerf7e36092016-06-23 00:15:04 +00008885 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008886 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008887 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008888 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008890
David Majnemerf7e36092016-06-23 00:15:04 +00008891 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008892 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008894
8895 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008897 D.getLBracketLoc(),
8898 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008899
David Majnemerf7e36092016-06-23 00:15:04 +00008900 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8901 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008902
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008903 ArrayExprs.push_back(Start.get());
8904 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008905 }
Mike Stump11289f42009-09-09 15:08:12 +00008906
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 if (!getDerived().AlwaysRebuild() &&
8908 Init.get() == E->getInit() &&
8909 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008910 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008911
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008912 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008913 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008914 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008915}
Mike Stump11289f42009-09-09 15:08:12 +00008916
Yunzhong Gaocb779302015-06-10 00:27:52 +00008917// Seems that if TransformInitListExpr() only works on the syntactic form of an
8918// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8919template<typename Derived>
8920ExprResult
8921TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8922 DesignatedInitUpdateExpr *E) {
8923 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8924 "initializer");
8925 return ExprError();
8926}
8927
8928template<typename Derived>
8929ExprResult
8930TreeTransform<Derived>::TransformNoInitExpr(
8931 NoInitExpr *E) {
8932 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8933 return ExprError();
8934}
8935
Douglas Gregora16548e2009-08-11 05:31:07 +00008936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008937ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008938TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008939 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008940 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008941
Douglas Gregor3da3c062009-10-28 00:29:27 +00008942 // FIXME: Will we ever have proper type location here? Will we actually
8943 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 QualType T = getDerived().TransformType(E->getType());
8945 if (T.isNull())
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 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008950 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008951
Douglas Gregora16548e2009-08-11 05:31:07 +00008952 return getDerived().RebuildImplicitValueInitExpr(T);
8953}
Mike Stump11289f42009-09-09 15:08:12 +00008954
Douglas Gregora16548e2009-08-11 05:31:07 +00008955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008956ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008957TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008958 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8959 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008961
John McCalldadc5752010-08-24 06:29:42 +00008962 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008963 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008965
Douglas Gregora16548e2009-08-11 05:31:07 +00008966 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008967 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008968 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008969 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008970
John McCallb268a282010-08-23 23:25:46 +00008971 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008972 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008973}
8974
8975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008977TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008978 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008979 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008980 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8981 &ArgumentChanged))
8982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008983
Douglas Gregora16548e2009-08-11 05:31:07 +00008984 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008985 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 E->getRParenLoc());
8987}
Mike Stump11289f42009-09-09 15:08:12 +00008988
Douglas Gregora16548e2009-08-11 05:31:07 +00008989/// \brief Transform an address-of-label expression.
8990///
8991/// By default, the transformation of an address-of-label expression always
8992/// rebuilds the expression, so that the label identifier can be resolved to
8993/// the corresponding label statement by semantic analysis.
8994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008995ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008996TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008997 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8998 E->getLabel());
8999 if (!LD)
9000 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009001
Douglas Gregora16548e2009-08-11 05:31:07 +00009002 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009003 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009004}
Mike Stump11289f42009-09-09 15:08:12 +00009005
9006template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009008TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009009 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009010 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009012 if (SubStmt.isInvalid()) {
9013 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009014 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009015 }
Mike Stump11289f42009-09-09 15:08:12 +00009016
Douglas Gregora16548e2009-08-11 05:31:07 +00009017 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009018 SubStmt.get() == E->getSubStmt()) {
9019 // Calling this an 'error' is unintuitive, but it does the right thing.
9020 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009021 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009022 }
Mike Stump11289f42009-09-09 15:08:12 +00009023
9024 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009025 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009026 E->getRParenLoc());
9027}
Mike Stump11289f42009-09-09 15:08:12 +00009028
Douglas Gregora16548e2009-08-11 05:31:07 +00009029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009030ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009031TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009032 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009033 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009035
John McCalldadc5752010-08-24 06:29:42 +00009036 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009037 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009039
John McCalldadc5752010-08-24 06:29:42 +00009040 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009041 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009043
Douglas Gregora16548e2009-08-11 05:31:07 +00009044 if (!getDerived().AlwaysRebuild() &&
9045 Cond.get() == E->getCond() &&
9046 LHS.get() == E->getLHS() &&
9047 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009048 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009049
Douglas Gregora16548e2009-08-11 05:31:07 +00009050 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009051 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 E->getRParenLoc());
9053}
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009057TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009058 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009059}
9060
9061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009063TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009064 switch (E->getOperator()) {
9065 case OO_New:
9066 case OO_Delete:
9067 case OO_Array_New:
9068 case OO_Array_Delete:
9069 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009070
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009071 case OO_Call: {
9072 // This is a call to an object's operator().
9073 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9074
9075 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009076 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009077 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009078 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009079
9080 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009081 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9082 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009083
9084 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009085 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009086 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009087 Args))
9088 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009089
John McCallb268a282010-08-23 23:25:46 +00009090 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009091 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009092 E->getLocEnd());
9093 }
9094
9095#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9096 case OO_##Name:
9097#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9098#include "clang/Basic/OperatorKinds.def"
9099 case OO_Subscript:
9100 // Handled below.
9101 break;
9102
9103 case OO_Conditional:
9104 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009105
9106 case OO_None:
9107 case NUM_OVERLOADED_OPERATORS:
9108 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009109 }
9110
John McCalldadc5752010-08-24 06:29:42 +00009111 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009112 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009114
Richard Smithdb2630f2012-10-21 03:28:35 +00009115 ExprResult First;
9116 if (E->getOperator() == OO_Amp)
9117 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9118 else
9119 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009122
John McCalldadc5752010-08-24 06:29:42 +00009123 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (E->getNumArgs() == 2) {
9125 Second = getDerived().TransformExpr(E->getArg(1));
9126 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009127 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009128 }
Mike Stump11289f42009-09-09 15:08:12 +00009129
Douglas Gregora16548e2009-08-11 05:31:07 +00009130 if (!getDerived().AlwaysRebuild() &&
9131 Callee.get() == E->getCallee() &&
9132 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009133 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009134 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009135
Lang Hames5de91cc2012-10-02 04:45:10 +00009136 Sema::FPContractStateRAII FPContractState(getSema());
9137 getSema().FPFeatures.fp_contract = E->isFPContractable();
9138
Douglas Gregora16548e2009-08-11 05:31:07 +00009139 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9140 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009141 Callee.get(),
9142 First.get(),
9143 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009144}
Mike Stump11289f42009-09-09 15:08:12 +00009145
Douglas Gregora16548e2009-08-11 05:31:07 +00009146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009148TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9149 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009150}
Mike Stump11289f42009-09-09 15:08:12 +00009151
Douglas Gregora16548e2009-08-11 05:31:07 +00009152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009153ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009154TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9155 // Transform the callee.
9156 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9157 if (Callee.isInvalid())
9158 return ExprError();
9159
9160 // Transform exec config.
9161 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9162 if (EC.isInvalid())
9163 return ExprError();
9164
9165 // Transform arguments.
9166 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009167 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009168 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009169 &ArgChanged))
9170 return ExprError();
9171
9172 if (!getDerived().AlwaysRebuild() &&
9173 Callee.get() == E->getCallee() &&
9174 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009175 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009176
9177 // FIXME: Wrong source location information for the '('.
9178 SourceLocation FakeLParenLoc
9179 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9180 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009181 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009182 E->getRParenLoc(), EC.get());
9183}
9184
9185template<typename Derived>
9186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009187TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009188 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9189 if (!Type)
9190 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009191
John McCalldadc5752010-08-24 06:29:42 +00009192 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009193 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009196
Douglas Gregora16548e2009-08-11 05:31:07 +00009197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009198 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009199 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009200 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009201 return getDerived().RebuildCXXNamedCastExpr(
9202 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9203 Type, E->getAngleBrackets().getEnd(),
9204 // FIXME. this should be '(' location
9205 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009206}
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregora16548e2009-08-11 05:31:07 +00009208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009210TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9211 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009212}
Mike Stump11289f42009-09-09 15:08:12 +00009213
9214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009216TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9217 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009218}
9219
Douglas Gregora16548e2009-08-11 05:31:07 +00009220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009221ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009222TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009223 CXXReinterpretCastExpr *E) {
9224 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009225}
Mike Stump11289f42009-09-09 15:08:12 +00009226
Douglas Gregora16548e2009-08-11 05:31:07 +00009227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009229TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9230 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
Mike Stump11289f42009-09-09 15:08:12 +00009232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009235TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009236 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009237 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9238 if (!Type)
9239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009240
John McCalldadc5752010-08-24 06:29:42 +00009241 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009242 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009243 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009245
Douglas Gregora16548e2009-08-11 05:31:07 +00009246 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009247 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009248 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009249 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009250
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009251 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009252 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009253 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009254 E->getRParenLoc());
9255}
Mike Stump11289f42009-09-09 15:08:12 +00009256
Douglas Gregora16548e2009-08-11 05:31:07 +00009257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009259TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009260 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009261 TypeSourceInfo *TInfo
9262 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9263 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregora16548e2009-08-11 05:31:07 +00009266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009267 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009268 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009269
Douglas Gregor9da64192010-04-26 22:37:10 +00009270 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9271 E->getLocStart(),
9272 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009273 E->getLocEnd());
9274 }
Mike Stump11289f42009-09-09 15:08:12 +00009275
Eli Friedman456f0182012-01-20 01:26:23 +00009276 // We don't know whether the subexpression is potentially evaluated until
9277 // after we perform semantic analysis. We speculatively assume it is
9278 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009279 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009280 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9281 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009282
John McCalldadc5752010-08-24 06:29:42 +00009283 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009286
Douglas Gregora16548e2009-08-11 05:31:07 +00009287 if (!getDerived().AlwaysRebuild() &&
9288 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009289 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009290
Douglas Gregor9da64192010-04-26 22:37:10 +00009291 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9292 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009293 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009294 E->getLocEnd());
9295}
9296
9297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009298ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009299TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9300 if (E->isTypeOperand()) {
9301 TypeSourceInfo *TInfo
9302 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9303 if (!TInfo)
9304 return ExprError();
9305
9306 if (!getDerived().AlwaysRebuild() &&
9307 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009308 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009309
Douglas Gregor69735112011-03-06 17:40:41 +00009310 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009311 E->getLocStart(),
9312 TInfo,
9313 E->getLocEnd());
9314 }
9315
Francois Pichet9f4f2072010-09-08 12:20:18 +00009316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9317
9318 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9319 if (SubExpr.isInvalid())
9320 return ExprError();
9321
9322 if (!getDerived().AlwaysRebuild() &&
9323 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009324 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009325
9326 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9327 E->getLocStart(),
9328 SubExpr.get(),
9329 E->getLocEnd());
9330}
9331
9332template<typename Derived>
9333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009334TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009335 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009336}
Mike Stump11289f42009-09-09 15:08:12 +00009337
Douglas Gregora16548e2009-08-11 05:31:07 +00009338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009339ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009340TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009341 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009342 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009343}
Mike Stump11289f42009-09-09 15:08:12 +00009344
Douglas Gregora16548e2009-08-11 05:31:07 +00009345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009346ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009347TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009348 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009349
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009350 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9351 // Make sure that we capture 'this'.
9352 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009353 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009355
Douglas Gregorb15af892010-01-07 23:12:05 +00009356 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009357}
Mike Stump11289f42009-09-09 15:08:12 +00009358
Douglas Gregora16548e2009-08-11 05:31:07 +00009359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009361TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009362 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009363 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009365
Douglas Gregora16548e2009-08-11 05:31:07 +00009366 if (!getDerived().AlwaysRebuild() &&
9367 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009368 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009369
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009370 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9371 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009372}
Mike Stump11289f42009-09-09 15:08:12 +00009373
Douglas Gregora16548e2009-08-11 05:31:07 +00009374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009376TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009377 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009378 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9379 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009380 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009382
Chandler Carruth794da4c2010-02-08 06:42:49 +00009383 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009384 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009385 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009386
Douglas Gregor033f6752009-12-23 23:03:06 +00009387 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009388}
Mike Stump11289f42009-09-09 15:08:12 +00009389
Douglas Gregora16548e2009-08-11 05:31:07 +00009390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009391ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009392TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9393 FieldDecl *Field
9394 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9395 E->getField()));
9396 if (!Field)
9397 return ExprError();
9398
9399 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009400 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009401
9402 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9403}
9404
9405template<typename Derived>
9406ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009407TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9408 CXXScalarValueInitExpr *E) {
9409 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9410 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009411 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009412
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009414 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009415 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009416
Chad Rosier1dcde962012-08-08 18:46:20 +00009417 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009418 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009419 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009420}
Mike Stump11289f42009-09-09 15:08:12 +00009421
Douglas Gregora16548e2009-08-11 05:31:07 +00009422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009424TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009425 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009426 TypeSourceInfo *AllocTypeInfo
9427 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9428 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009430
Douglas Gregora16548e2009-08-11 05:31:07 +00009431 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009432 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009435
Douglas Gregora16548e2009-08-11 05:31:07 +00009436 // Transform the placement arguments (if any).
9437 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009438 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009439 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009440 E->getNumPlacementArgs(), true,
9441 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009443
Sebastian Redl6047f072012-02-16 12:22:20 +00009444 // Transform the initializer (if any).
9445 Expr *OldInit = E->getInitializer();
9446 ExprResult NewInit;
9447 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009448 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009449 if (NewInit.isInvalid())
9450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009451
Sebastian Redl6047f072012-02-16 12:22:20 +00009452 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009453 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009454 if (E->getOperatorNew()) {
9455 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009456 getDerived().TransformDecl(E->getLocStart(),
9457 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009458 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009459 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009460 }
9461
Craig Topperc3ec1492014-05-26 06:22:03 +00009462 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009463 if (E->getOperatorDelete()) {
9464 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009465 getDerived().TransformDecl(E->getLocStart(),
9466 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009467 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009468 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009470
Douglas Gregora16548e2009-08-11 05:31:07 +00009471 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009472 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009473 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009474 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009475 OperatorNew == E->getOperatorNew() &&
9476 OperatorDelete == E->getOperatorDelete() &&
9477 !ArgumentChanged) {
9478 // Mark any declarations we need as referenced.
9479 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009480 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009481 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009482 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009483 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009484
Sebastian Redl6047f072012-02-16 12:22:20 +00009485 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009486 QualType ElementType
9487 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9488 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9489 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9490 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009491 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009492 }
9493 }
9494 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009495
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009496 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009497 }
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregor0744ef62010-09-07 21:49:58 +00009499 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009500 if (!ArraySize.get()) {
9501 // If no array size was specified, but the new expression was
9502 // instantiated with an array type (e.g., "new T" where T is
9503 // instantiated with "int[4]"), extract the outer bound from the
9504 // array type as our array size. We do this with constant and
9505 // dependently-sized array types.
9506 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9507 if (!ArrayT) {
9508 // Do nothing
9509 } else if (const ConstantArrayType *ConsArrayT
9510 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009511 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9512 SemaRef.Context.getSizeType(),
9513 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009514 AllocType = ConsArrayT->getElementType();
9515 } else if (const DependentSizedArrayType *DepArrayT
9516 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9517 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009518 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009519 AllocType = DepArrayT->getElementType();
9520 }
9521 }
9522 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009523
Douglas Gregora16548e2009-08-11 05:31:07 +00009524 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9525 E->isGlobalNew(),
9526 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009527 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009528 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009529 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009530 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009531 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009532 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009533 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009534 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009535}
Mike Stump11289f42009-09-09 15:08:12 +00009536
Douglas Gregora16548e2009-08-11 05:31:07 +00009537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009539TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009540 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009541 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009543
Douglas Gregord2d9da02010-02-26 00:38:10 +00009544 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009545 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009546 if (E->getOperatorDelete()) {
9547 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009548 getDerived().TransformDecl(E->getLocStart(),
9549 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009550 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009551 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009553
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009555 Operand.get() == E->getArgument() &&
9556 OperatorDelete == E->getOperatorDelete()) {
9557 // Mark any declarations we need as referenced.
9558 // FIXME: instantiation-specific.
9559 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009560 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009561
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009562 if (!E->getArgument()->isTypeDependent()) {
9563 QualType Destroyed = SemaRef.Context.getBaseElementType(
9564 E->getDestroyedType());
9565 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9566 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009567 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009568 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009569 }
9570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009571
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009572 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009573 }
Mike Stump11289f42009-09-09 15:08:12 +00009574
Douglas Gregora16548e2009-08-11 05:31:07 +00009575 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9576 E->isGlobalDelete(),
9577 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009578 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009579}
Mike Stump11289f42009-09-09 15:08:12 +00009580
Douglas Gregora16548e2009-08-11 05:31:07 +00009581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009582ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009583TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009584 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009585 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009588
John McCallba7bf592010-08-24 05:47:05 +00009589 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009590 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009591 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009592 E->getOperatorLoc(),
9593 E->isArrow()? tok::arrow : tok::period,
9594 ObjectTypePtr,
9595 MayBePseudoDestructor);
9596 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009597 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009598
John McCallba7bf592010-08-24 05:47:05 +00009599 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009600 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9601 if (QualifierLoc) {
9602 QualifierLoc
9603 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9604 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009605 return ExprError();
9606 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009607 CXXScopeSpec SS;
9608 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009609
Douglas Gregor678f90d2010-02-25 01:56:36 +00009610 PseudoDestructorTypeStorage Destroyed;
9611 if (E->getDestroyedTypeInfo()) {
9612 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009613 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009614 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009615 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009616 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009617 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009618 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009619 // We aren't likely to be able to resolve the identifier down to a type
9620 // now anyway, so just retain the identifier.
9621 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9622 E->getDestroyedTypeLoc());
9623 } else {
9624 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009625 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009626 *E->getDestroyedTypeIdentifier(),
9627 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009628 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009629 SS, ObjectTypePtr,
9630 false);
9631 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009632 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009633
Douglas Gregor678f90d2010-02-25 01:56:36 +00009634 Destroyed
9635 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9636 E->getDestroyedTypeLoc());
9637 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009638
Craig Topperc3ec1492014-05-26 06:22:03 +00009639 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009640 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009641 CXXScopeSpec EmptySS;
9642 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009643 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009644 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009645 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009646 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009647
John McCallb268a282010-08-23 23:25:46 +00009648 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009649 E->getOperatorLoc(),
9650 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009651 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009652 ScopeTypeInfo,
9653 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009654 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009655 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009656}
Mike Stump11289f42009-09-09 15:08:12 +00009657
Douglas Gregorad8a3362009-09-04 17:36:40 +00009658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009659ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009660TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009661 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009662 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9663 Sema::LookupOrdinaryName);
9664
9665 // Transform all the decls.
9666 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9667 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009668 NamedDecl *InstD = static_cast<NamedDecl*>(
9669 getDerived().TransformDecl(Old->getNameLoc(),
9670 *I));
John McCall84d87672009-12-10 09:41:52 +00009671 if (!InstD) {
9672 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9673 // This can happen because of dependent hiding.
9674 if (isa<UsingShadowDecl>(*I))
9675 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009676 else {
9677 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009678 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009679 }
John McCall84d87672009-12-10 09:41:52 +00009680 }
John McCalle66edc12009-11-24 19:00:30 +00009681
9682 // Expand using declarations.
9683 if (isa<UsingDecl>(InstD)) {
9684 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009685 for (auto *I : UD->shadows())
9686 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009687 continue;
9688 }
9689
9690 R.addDecl(InstD);
9691 }
9692
9693 // Resolve a kind, but don't do any further analysis. If it's
9694 // ambiguous, the callee needs to deal with it.
9695 R.resolveKind();
9696
9697 // Rebuild the nested-name qualifier, if present.
9698 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009699 if (Old->getQualifierLoc()) {
9700 NestedNameSpecifierLoc QualifierLoc
9701 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9702 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009704
Douglas Gregor0da1d432011-02-28 20:01:57 +00009705 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009706 }
9707
Douglas Gregor9262f472010-04-27 18:19:34 +00009708 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009709 CXXRecordDecl *NamingClass
9710 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9711 Old->getNameLoc(),
9712 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009713 if (!NamingClass) {
9714 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009715 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009717
Douglas Gregorda7be082010-04-27 16:10:10 +00009718 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009719 }
9720
Abramo Bagnara7945c982012-01-27 09:46:47 +00009721 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9722
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009723 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009724 // it's a normal declaration name or member reference.
9725 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9726 NamedDecl *D = R.getAsSingle<NamedDecl>();
9727 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9728 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9729 // give a good diagnostic.
9730 if (D && D->isCXXInstanceMember()) {
9731 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9732 /*TemplateArgs=*/nullptr,
9733 /*Scope=*/nullptr);
9734 }
9735
John McCalle66edc12009-11-24 19:00:30 +00009736 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009737 }
John McCalle66edc12009-11-24 19:00:30 +00009738
9739 // If we have template arguments, rebuild them, then rebuild the
9740 // templateid expression.
9741 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009742 if (Old->hasExplicitTemplateArgs() &&
9743 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009744 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009745 TransArgs)) {
9746 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009747 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009748 }
John McCalle66edc12009-11-24 19:00:30 +00009749
Abramo Bagnara7945c982012-01-27 09:46:47 +00009750 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009751 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009752}
Mike Stump11289f42009-09-09 15:08:12 +00009753
Douglas Gregora16548e2009-08-11 05:31:07 +00009754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009755ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009756TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9757 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009758 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009759 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9760 TypeSourceInfo *From = E->getArg(I);
9761 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009762 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009763 TypeLocBuilder TLB;
9764 TLB.reserve(FromTL.getFullDataSize());
9765 QualType To = getDerived().TransformType(TLB, FromTL);
9766 if (To.isNull())
9767 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009768
Douglas Gregor29c42f22012-02-24 07:38:34 +00009769 if (To == From->getType())
9770 Args.push_back(From);
9771 else {
9772 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9773 ArgChanged = true;
9774 }
9775 continue;
9776 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009777
Douglas Gregor29c42f22012-02-24 07:38:34 +00009778 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009779
Douglas Gregor29c42f22012-02-24 07:38:34 +00009780 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009781 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009782 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9783 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9784 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009785
Douglas Gregor29c42f22012-02-24 07:38:34 +00009786 // Determine whether the set of unexpanded parameter packs can and should
9787 // be expanded.
9788 bool Expand = true;
9789 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009790 Optional<unsigned> OrigNumExpansions =
9791 ExpansionTL.getTypePtr()->getNumExpansions();
9792 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009793 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9794 PatternTL.getSourceRange(),
9795 Unexpanded,
9796 Expand, RetainExpansion,
9797 NumExpansions))
9798 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009799
Douglas Gregor29c42f22012-02-24 07:38:34 +00009800 if (!Expand) {
9801 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009802 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009803 // expansion.
9804 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009805
Douglas Gregor29c42f22012-02-24 07:38:34 +00009806 TypeLocBuilder TLB;
9807 TLB.reserve(From->getTypeLoc().getFullDataSize());
9808
9809 QualType To = getDerived().TransformType(TLB, PatternTL);
9810 if (To.isNull())
9811 return ExprError();
9812
Chad Rosier1dcde962012-08-08 18:46:20 +00009813 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009814 PatternTL.getSourceRange(),
9815 ExpansionTL.getEllipsisLoc(),
9816 NumExpansions);
9817 if (To.isNull())
9818 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009819
Douglas Gregor29c42f22012-02-24 07:38:34 +00009820 PackExpansionTypeLoc ToExpansionTL
9821 = TLB.push<PackExpansionTypeLoc>(To);
9822 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9823 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9824 continue;
9825 }
9826
9827 // Expand the pack expansion by substituting for each argument in the
9828 // pack(s).
9829 for (unsigned I = 0; I != *NumExpansions; ++I) {
9830 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9831 TypeLocBuilder TLB;
9832 TLB.reserve(PatternTL.getFullDataSize());
9833 QualType To = getDerived().TransformType(TLB, PatternTL);
9834 if (To.isNull())
9835 return ExprError();
9836
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009837 if (To->containsUnexpandedParameterPack()) {
9838 To = getDerived().RebuildPackExpansionType(To,
9839 PatternTL.getSourceRange(),
9840 ExpansionTL.getEllipsisLoc(),
9841 NumExpansions);
9842 if (To.isNull())
9843 return ExprError();
9844
9845 PackExpansionTypeLoc ToExpansionTL
9846 = TLB.push<PackExpansionTypeLoc>(To);
9847 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9848 }
9849
Douglas Gregor29c42f22012-02-24 07:38:34 +00009850 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009852
Douglas Gregor29c42f22012-02-24 07:38:34 +00009853 if (!RetainExpansion)
9854 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009855
Douglas Gregor29c42f22012-02-24 07:38:34 +00009856 // If we're supposed to retain a pack expansion, do so by temporarily
9857 // forgetting the partially-substituted parameter pack.
9858 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9859
9860 TypeLocBuilder TLB;
9861 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009862
Douglas Gregor29c42f22012-02-24 07:38:34 +00009863 QualType To = getDerived().TransformType(TLB, PatternTL);
9864 if (To.isNull())
9865 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009866
9867 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009868 PatternTL.getSourceRange(),
9869 ExpansionTL.getEllipsisLoc(),
9870 NumExpansions);
9871 if (To.isNull())
9872 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009873
Douglas Gregor29c42f22012-02-24 07:38:34 +00009874 PackExpansionTypeLoc ToExpansionTL
9875 = TLB.push<PackExpansionTypeLoc>(To);
9876 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9877 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009879
Douglas Gregor29c42f22012-02-24 07:38:34 +00009880 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009881 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009882
9883 return getDerived().RebuildTypeTrait(E->getTrait(),
9884 E->getLocStart(),
9885 Args,
9886 E->getLocEnd());
9887}
9888
9889template<typename Derived>
9890ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009891TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9892 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9893 if (!T)
9894 return ExprError();
9895
9896 if (!getDerived().AlwaysRebuild() &&
9897 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009898 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009899
9900 ExprResult SubExpr;
9901 {
9902 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9903 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9904 if (SubExpr.isInvalid())
9905 return ExprError();
9906
9907 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009908 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009909 }
9910
9911 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9912 E->getLocStart(),
9913 T,
9914 SubExpr.get(),
9915 E->getLocEnd());
9916}
9917
9918template<typename Derived>
9919ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009920TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9921 ExprResult SubExpr;
9922 {
9923 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9924 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9925 if (SubExpr.isInvalid())
9926 return ExprError();
9927
9928 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009929 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009930 }
9931
9932 return getDerived().RebuildExpressionTrait(
9933 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9934}
9935
Reid Kleckner32506ed2014-06-12 23:03:48 +00009936template <typename Derived>
9937ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9938 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9939 TypeSourceInfo **RecoveryTSI) {
9940 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9941 DRE, AddrTaken, RecoveryTSI);
9942
9943 // Propagate both errors and recovered types, which return ExprEmpty.
9944 if (!NewDRE.isUsable())
9945 return NewDRE;
9946
9947 // We got an expr, wrap it up in parens.
9948 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9949 return PE;
9950 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9951 PE->getRParen());
9952}
9953
9954template <typename Derived>
9955ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9956 DependentScopeDeclRefExpr *E) {
9957 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9958 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009959}
9960
9961template<typename Derived>
9962ExprResult
9963TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9964 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009965 bool IsAddressOfOperand,
9966 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009967 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009968 NestedNameSpecifierLoc QualifierLoc
9969 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9970 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009971 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009972 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009973
John McCall31f82722010-11-12 08:19:04 +00009974 // TODO: If this is a conversion-function-id, verify that the
9975 // destination type name (if present) resolves the same way after
9976 // instantiation as it did in the local scope.
9977
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009978 DeclarationNameInfo NameInfo
9979 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9980 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009982
John McCalle66edc12009-11-24 19:00:30 +00009983 if (!E->hasExplicitTemplateArgs()) {
9984 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009985 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009986 // Note: it is sufficient to compare the Name component of NameInfo:
9987 // if name has not changed, DNLoc has not changed either.
9988 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009989 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009990
Reid Kleckner32506ed2014-06-12 23:03:48 +00009991 return getDerived().RebuildDependentScopeDeclRefExpr(
9992 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9993 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009994 }
John McCall6b51f282009-11-23 01:53:49 +00009995
9996 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009997 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9998 E->getNumTemplateArgs(),
9999 TransArgs))
10000 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010001
Reid Kleckner32506ed2014-06-12 23:03:48 +000010002 return getDerived().RebuildDependentScopeDeclRefExpr(
10003 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10004 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010005}
10006
10007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010009TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010010 // CXXConstructExprs other than for list-initialization and
10011 // CXXTemporaryObjectExpr are always implicit, so when we have
10012 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010013 if ((E->getNumArgs() == 1 ||
10014 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010015 (!getDerived().DropCallArgument(E->getArg(0))) &&
10016 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010017 return getDerived().TransformExpr(E->getArg(0));
10018
Douglas Gregora16548e2009-08-11 05:31:07 +000010019 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10020
10021 QualType T = getDerived().TransformType(E->getType());
10022 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010023 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010024
10025 CXXConstructorDecl *Constructor
10026 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010027 getDerived().TransformDecl(E->getLocStart(),
10028 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010029 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010033 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010034 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010035 &ArgumentChanged))
10036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010037
Douglas Gregora16548e2009-08-11 05:31:07 +000010038 if (!getDerived().AlwaysRebuild() &&
10039 T == E->getType() &&
10040 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010041 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010042 // Mark the constructor as referenced.
10043 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010044 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010045 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010046 }
Mike Stump11289f42009-09-09 15:08:12 +000010047
Douglas Gregordb121ba2009-12-14 16:27:04 +000010048 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010049 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010050 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010051 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010052 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010053 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010054 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010055 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010056 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010057}
Mike Stump11289f42009-09-09 15:08:12 +000010058
Richard Smith5179eb72016-06-28 19:03:57 +000010059template<typename Derived>
10060ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10061 CXXInheritedCtorInitExpr *E) {
10062 QualType T = getDerived().TransformType(E->getType());
10063 if (T.isNull())
10064 return ExprError();
10065
10066 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10067 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10068 if (!Constructor)
10069 return ExprError();
10070
10071 if (!getDerived().AlwaysRebuild() &&
10072 T == E->getType() &&
10073 Constructor == E->getConstructor()) {
10074 // Mark the constructor as referenced.
10075 // FIXME: Instantiation-specific
10076 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10077 return E;
10078 }
10079
10080 return getDerived().RebuildCXXInheritedCtorInitExpr(
10081 T, E->getLocation(), Constructor,
10082 E->constructsVBase(), E->inheritedFromVBase());
10083}
10084
Douglas Gregora16548e2009-08-11 05:31:07 +000010085/// \brief Transform a C++ temporary-binding expression.
10086///
Douglas Gregor363b1512009-12-24 18:51:59 +000010087/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10088/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010091TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010092 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010093}
Mike Stump11289f42009-09-09 15:08:12 +000010094
John McCall5d413782010-12-06 08:20:24 +000010095/// \brief Transform a C++ expression that contains cleanups that should
10096/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010097///
John McCall5d413782010-12-06 08:20:24 +000010098/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010099/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010101ExprResult
John McCall5d413782010-12-06 08:20:24 +000010102TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010103 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010104}
Mike Stump11289f42009-09-09 15:08:12 +000010105
Douglas Gregora16548e2009-08-11 05:31:07 +000010106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010107ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010108TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010109 CXXTemporaryObjectExpr *E) {
10110 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10111 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010112 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010113
Douglas Gregora16548e2009-08-11 05:31:07 +000010114 CXXConstructorDecl *Constructor
10115 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010116 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010117 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010118 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010120
Douglas Gregora16548e2009-08-11 05:31:07 +000010121 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010122 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010123 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010124 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010125 &ArgumentChanged))
10126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010127
Douglas Gregora16548e2009-08-11 05:31:07 +000010128 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010129 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010130 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010131 !ArgumentChanged) {
10132 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010133 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010134 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010135 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010136
Richard Smithd59b8322012-12-19 01:39:02 +000010137 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010138 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10139 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010140 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010141 E->getLocEnd());
10142}
Mike Stump11289f42009-09-09 15:08:12 +000010143
Douglas Gregora16548e2009-08-11 05:31:07 +000010144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010145ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010146TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010147 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010148 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010149 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010150 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10151 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010152 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010153 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010154 CEnd = E->capture_end();
10155 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010156 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010157 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010158 EnterExpressionEvaluationContext EEEC(getSema(),
10159 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010160 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10161 C->getCapturedVar()->getInit(),
10162 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010163
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010164 if (NewExprInitResult.isInvalid())
10165 return ExprError();
10166 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010167
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010168 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010169 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010170 getSema().buildLambdaInitCaptureInitialization(
10171 C->getLocation(), OldVD->getType()->isReferenceType(),
10172 OldVD->getIdentifier(),
10173 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010174 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010175 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10176 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010177 }
10178
Faisal Vali2cba1332013-10-23 06:44:28 +000010179 // Transform the template parameters, and add them to the current
10180 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010181 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010182 E->getTemplateParameterList());
10183
Richard Smith01014ce2014-11-20 23:53:14 +000010184 // Transform the type of the original lambda's call operator.
10185 // The transformation MUST be done in the CurrentInstantiationScope since
10186 // it introduces a mapping of the original to the newly created
10187 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010188 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010189 {
10190 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10191 FunctionProtoTypeLoc OldCallOpFPTL =
10192 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010193
10194 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010195 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010196 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010197 QualType NewCallOpType = TransformFunctionProtoType(
10198 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010199 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10200 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10201 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010202 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010203 if (NewCallOpType.isNull())
10204 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010205 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10206 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010207 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010208
Richard Smithc38498f2015-04-27 21:27:54 +000010209 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10210 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10211 LSI->GLTemplateParameterList = TPL;
10212
Eli Friedmand564afb2012-09-19 01:18:11 +000010213 // Create the local class that will describe the lambda.
10214 CXXRecordDecl *Class
10215 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010216 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010217 /*KnownDependent=*/false,
10218 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010219 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10220
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010221 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010222 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10223 Class, E->getIntroducerRange(), NewCallOpTSI,
10224 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010225 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10226 E->getCallOperator()->isConstexpr());
10227
Faisal Vali2cba1332013-10-23 06:44:28 +000010228 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010229
Faisal Vali2cba1332013-10-23 06:44:28 +000010230 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010231 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010232
Douglas Gregorb4328232012-02-14 00:00:48 +000010233 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010234 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010235 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010236
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010237 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010238 getSema().buildLambdaScope(LSI, NewCallOperator,
10239 E->getIntroducerRange(),
10240 E->getCaptureDefault(),
10241 E->getCaptureDefaultLoc(),
10242 E->hasExplicitParameters(),
10243 E->hasExplicitResultType(),
10244 E->isMutable());
10245
10246 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010247
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010248 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010249 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010250 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010251 CEnd = E->capture_end();
10252 C != CEnd; ++C) {
10253 // When we hit the first implicit capture, tell Sema that we've finished
10254 // the list of explicit captures.
10255 if (!FinishedExplicitCaptures && C->isImplicit()) {
10256 getSema().finishLambdaExplicitCaptures(LSI);
10257 FinishedExplicitCaptures = true;
10258 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010259
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010260 // Capturing 'this' is trivial.
10261 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010262 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10263 /*BuildAndDiagnose*/ true, nullptr,
10264 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010265 continue;
10266 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010267 // Captured expression will be recaptured during captured variables
10268 // rebuilding.
10269 if (C->capturesVLAType())
10270 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010271
Richard Smithba71c082013-05-16 06:20:58 +000010272 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010273 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010274 InitCaptureInfoTy InitExprTypePair =
10275 InitCaptureExprsAndTypes[C - E->capture_begin()];
10276 ExprResult Init = InitExprTypePair.first;
10277 QualType InitQualType = InitExprTypePair.second;
10278 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010279 Invalid = true;
10280 continue;
10281 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010282 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010283 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010284 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10285 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010286 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010287 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010288 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010289 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010290 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010291 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010292 continue;
10293 }
10294
10295 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10296
Douglas Gregor3e308b12012-02-14 19:27:52 +000010297 // Determine the capture kind for Sema.
10298 Sema::TryCaptureKind Kind
10299 = C->isImplicit()? Sema::TryCapture_Implicit
10300 : C->getCaptureKind() == LCK_ByCopy
10301 ? Sema::TryCapture_ExplicitByVal
10302 : Sema::TryCapture_ExplicitByRef;
10303 SourceLocation EllipsisLoc;
10304 if (C->isPackExpansion()) {
10305 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10306 bool ShouldExpand = false;
10307 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010308 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010309 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10310 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010311 Unexpanded,
10312 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010313 NumExpansions)) {
10314 Invalid = true;
10315 continue;
10316 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010317
Douglas Gregor3e308b12012-02-14 19:27:52 +000010318 if (ShouldExpand) {
10319 // The transform has determined that we should perform an expansion;
10320 // transform and capture each of the arguments.
10321 // expansion of the pattern. Do so.
10322 VarDecl *Pack = C->getCapturedVar();
10323 for (unsigned I = 0; I != *NumExpansions; ++I) {
10324 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10325 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010326 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010327 Pack));
10328 if (!CapturedVar) {
10329 Invalid = true;
10330 continue;
10331 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010332
Douglas Gregor3e308b12012-02-14 19:27:52 +000010333 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010334 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10335 }
Richard Smith9467be42014-06-06 17:33:35 +000010336
10337 // FIXME: Retain a pack expansion if RetainExpansion is true.
10338
Douglas Gregor3e308b12012-02-14 19:27:52 +000010339 continue;
10340 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010341
Douglas Gregor3e308b12012-02-14 19:27:52 +000010342 EllipsisLoc = C->getEllipsisLoc();
10343 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010344
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010345 // Transform the captured variable.
10346 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010347 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010348 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010349 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010350 Invalid = true;
10351 continue;
10352 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010353
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010354 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010355 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10356 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010357 }
10358 if (!FinishedExplicitCaptures)
10359 getSema().finishLambdaExplicitCaptures(LSI);
10360
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010361 // Enter a new evaluation context to insulate the lambda from any
10362 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010363 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010364
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010365 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010366 StmtResult Body =
10367 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10368
10369 // ActOnLambda* will pop the function scope for us.
10370 FuncScopeCleanup.disable();
10371
Douglas Gregorb4328232012-02-14 00:00:48 +000010372 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010373 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010374 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010375 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010376 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010377 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010378
Richard Smithc38498f2015-04-27 21:27:54 +000010379 // Copy the LSI before ActOnFinishFunctionBody removes it.
10380 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10381 // the call operator.
10382 auto LSICopy = *LSI;
10383 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10384 /*IsInstantiation*/ true);
10385 SavedContext.pop();
10386
10387 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10388 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010389}
10390
10391template<typename Derived>
10392ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010393TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010394 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010395 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10396 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010398
Douglas Gregora16548e2009-08-11 05:31:07 +000010399 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010400 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010401 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010402 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010403 &ArgumentChanged))
10404 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010405
Douglas Gregora16548e2009-08-11 05:31:07 +000010406 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010407 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010408 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010409 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010410
Douglas Gregora16548e2009-08-11 05:31:07 +000010411 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010412 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010413 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010414 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010415 E->getRParenLoc());
10416}
Mike Stump11289f42009-09-09 15:08:12 +000010417
Douglas Gregora16548e2009-08-11 05:31:07 +000010418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010419ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010420TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010421 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010422 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010423 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010424 Expr *OldBase;
10425 QualType BaseType;
10426 QualType ObjectType;
10427 if (!E->isImplicitAccess()) {
10428 OldBase = E->getBase();
10429 Base = getDerived().TransformExpr(OldBase);
10430 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010432
John McCall2d74de92009-12-01 22:10:20 +000010433 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010434 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010435 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010436 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010437 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010438 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010439 ObjectTy,
10440 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010441 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010442 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010443
John McCallba7bf592010-08-24 05:47:05 +000010444 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010445 BaseType = ((Expr*) Base.get())->getType();
10446 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010447 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010448 BaseType = getDerived().TransformType(E->getBaseType());
10449 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10450 }
Mike Stump11289f42009-09-09 15:08:12 +000010451
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010452 // Transform the first part of the nested-name-specifier that qualifies
10453 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010454 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010455 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010456 E->getFirstQualifierFoundInScope(),
10457 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010458
Douglas Gregore16af532011-02-28 18:50:33 +000010459 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010460 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010461 QualifierLoc
10462 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10463 ObjectType,
10464 FirstQualifierInScope);
10465 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010466 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010467 }
Mike Stump11289f42009-09-09 15:08:12 +000010468
Abramo Bagnara7945c982012-01-27 09:46:47 +000010469 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10470
John McCall31f82722010-11-12 08:19:04 +000010471 // TODO: If this is a conversion-function-id, verify that the
10472 // destination type name (if present) resolves the same way after
10473 // instantiation as it did in the local scope.
10474
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010475 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010476 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010477 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010479
John McCall2d74de92009-12-01 22:10:20 +000010480 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010481 // This is a reference to a member without an explicitly-specified
10482 // template argument list. Optimize for this common case.
10483 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010484 Base.get() == OldBase &&
10485 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010486 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010487 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010488 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010489 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010490
John McCallb268a282010-08-23 23:25:46 +000010491 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010492 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010493 E->isArrow(),
10494 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010495 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010496 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010497 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010498 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010499 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010500 }
10501
John McCall6b51f282009-11-23 01:53:49 +000010502 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010503 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10504 E->getNumTemplateArgs(),
10505 TransArgs))
10506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010507
John McCallb268a282010-08-23 23:25:46 +000010508 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010509 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010510 E->isArrow(),
10511 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010512 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010513 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010514 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010515 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010516 &TransArgs);
10517}
10518
10519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010521TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010522 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010523 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010524 QualType BaseType;
10525 if (!Old->isImplicitAccess()) {
10526 Base = getDerived().TransformExpr(Old->getBase());
10527 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010528 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010529 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010530 Old->isArrow());
10531 if (Base.isInvalid())
10532 return ExprError();
10533 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010534 } else {
10535 BaseType = getDerived().TransformType(Old->getBaseType());
10536 }
John McCall10eae182009-11-30 22:42:35 +000010537
Douglas Gregor0da1d432011-02-28 20:01:57 +000010538 NestedNameSpecifierLoc QualifierLoc;
10539 if (Old->getQualifierLoc()) {
10540 QualifierLoc
10541 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10542 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010543 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010544 }
10545
Abramo Bagnara7945c982012-01-27 09:46:47 +000010546 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10547
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010548 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010549 Sema::LookupOrdinaryName);
10550
10551 // Transform all the decls.
10552 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10553 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010554 NamedDecl *InstD = static_cast<NamedDecl*>(
10555 getDerived().TransformDecl(Old->getMemberLoc(),
10556 *I));
John McCall84d87672009-12-10 09:41:52 +000010557 if (!InstD) {
10558 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10559 // This can happen because of dependent hiding.
10560 if (isa<UsingShadowDecl>(*I))
10561 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010562 else {
10563 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010564 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010565 }
John McCall84d87672009-12-10 09:41:52 +000010566 }
John McCall10eae182009-11-30 22:42:35 +000010567
10568 // Expand using declarations.
10569 if (isa<UsingDecl>(InstD)) {
10570 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010571 for (auto *I : UD->shadows())
10572 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010573 continue;
10574 }
10575
10576 R.addDecl(InstD);
10577 }
10578
10579 R.resolveKind();
10580
Douglas Gregor9262f472010-04-27 18:19:34 +000010581 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010582 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010583 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010584 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010585 Old->getMemberLoc(),
10586 Old->getNamingClass()));
10587 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010588 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010589
Douglas Gregorda7be082010-04-27 16:10:10 +000010590 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010591 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010592
John McCall10eae182009-11-30 22:42:35 +000010593 TemplateArgumentListInfo TransArgs;
10594 if (Old->hasExplicitTemplateArgs()) {
10595 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10596 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010597 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10598 Old->getNumTemplateArgs(),
10599 TransArgs))
10600 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010601 }
John McCall38836f02010-01-15 08:34:02 +000010602
10603 // FIXME: to do this check properly, we will need to preserve the
10604 // first-qualifier-in-scope here, just in case we had a dependent
10605 // base (and therefore couldn't do the check) and a
10606 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010607 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010608
John McCallb268a282010-08-23 23:25:46 +000010609 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010610 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010611 Old->getOperatorLoc(),
10612 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010613 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010614 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010615 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010616 R,
10617 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010618 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010619}
10620
10621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010622ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010623TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010624 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010625 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10626 if (SubExpr.isInvalid())
10627 return ExprError();
10628
10629 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010630 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010631
10632 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10633}
10634
10635template<typename Derived>
10636ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010637TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010638 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10639 if (Pattern.isInvalid())
10640 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010641
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010642 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010643 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010644
Douglas Gregorb8840002011-01-14 21:20:45 +000010645 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10646 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010647}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010648
10649template<typename Derived>
10650ExprResult
10651TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10652 // If E is not value-dependent, then nothing will change when we transform it.
10653 // Note: This is an instantiation-centric view.
10654 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010655 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010656
Richard Smithd784e682015-09-23 21:41:42 +000010657 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010658
Richard Smithd784e682015-09-23 21:41:42 +000010659 ArrayRef<TemplateArgument> PackArgs;
10660 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010661
Richard Smithd784e682015-09-23 21:41:42 +000010662 // Find the argument list to transform.
10663 if (E->isPartiallySubstituted()) {
10664 PackArgs = E->getPartialArguments();
10665 } else if (E->isValueDependent()) {
10666 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10667 bool ShouldExpand = false;
10668 bool RetainExpansion = false;
10669 Optional<unsigned> NumExpansions;
10670 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10671 Unexpanded,
10672 ShouldExpand, RetainExpansion,
10673 NumExpansions))
10674 return ExprError();
10675
10676 // If we need to expand the pack, build a template argument from it and
10677 // expand that.
10678 if (ShouldExpand) {
10679 auto *Pack = E->getPack();
10680 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10681 ArgStorage = getSema().Context.getPackExpansionType(
10682 getSema().Context.getTypeDeclType(TTPD), None);
10683 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10684 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10685 } else {
10686 auto *VD = cast<ValueDecl>(Pack);
10687 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10688 VK_RValue, E->getPackLoc());
10689 if (DRE.isInvalid())
10690 return ExprError();
10691 ArgStorage = new (getSema().Context) PackExpansionExpr(
10692 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10693 }
10694 PackArgs = ArgStorage;
10695 }
10696 }
10697
10698 // If we're not expanding the pack, just transform the decl.
10699 if (!PackArgs.size()) {
10700 auto *Pack = cast_or_null<NamedDecl>(
10701 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010702 if (!Pack)
10703 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010704 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10705 E->getPackLoc(),
10706 E->getRParenLoc(), None, None);
10707 }
10708
10709 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10710 E->getPackLoc());
10711 {
10712 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10713 typedef TemplateArgumentLocInventIterator<
10714 Derived, const TemplateArgument*> PackLocIterator;
10715 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10716 PackLocIterator(*this, PackArgs.end()),
10717 TransformedPackArgs, /*Uneval*/true))
10718 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010719 }
10720
Richard Smithd784e682015-09-23 21:41:42 +000010721 SmallVector<TemplateArgument, 8> Args;
10722 bool PartialSubstitution = false;
10723 for (auto &Loc : TransformedPackArgs.arguments()) {
10724 Args.push_back(Loc.getArgument());
10725 if (Loc.getArgument().isPackExpansion())
10726 PartialSubstitution = true;
10727 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010728
Richard Smithd784e682015-09-23 21:41:42 +000010729 if (PartialSubstitution)
10730 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10731 E->getPackLoc(),
10732 E->getRParenLoc(), None, Args);
10733
10734 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010735 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010736 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010737}
10738
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010739template<typename Derived>
10740ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010741TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10742 SubstNonTypeTemplateParmPackExpr *E) {
10743 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010744 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010745}
10746
10747template<typename Derived>
10748ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010749TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10750 SubstNonTypeTemplateParmExpr *E) {
10751 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010752 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010753}
10754
10755template<typename Derived>
10756ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010757TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10758 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010759 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010760}
10761
10762template<typename Derived>
10763ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010764TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10765 MaterializeTemporaryExpr *E) {
10766 return getDerived().TransformExpr(E->GetTemporaryExpr());
10767}
Chad Rosier1dcde962012-08-08 18:46:20 +000010768
Douglas Gregorfe314812011-06-21 17:03:29 +000010769template<typename Derived>
10770ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010771TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10772 Expr *Pattern = E->getPattern();
10773
10774 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10775 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10776 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10777
10778 // Determine whether the set of unexpanded parameter packs can and should
10779 // be expanded.
10780 bool Expand = true;
10781 bool RetainExpansion = false;
10782 Optional<unsigned> NumExpansions;
10783 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10784 Pattern->getSourceRange(),
10785 Unexpanded,
10786 Expand, RetainExpansion,
10787 NumExpansions))
10788 return true;
10789
10790 if (!Expand) {
10791 // Do not expand any packs here, just transform and rebuild a fold
10792 // expression.
10793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10794
10795 ExprResult LHS =
10796 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10797 if (LHS.isInvalid())
10798 return true;
10799
10800 ExprResult RHS =
10801 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10802 if (RHS.isInvalid())
10803 return true;
10804
10805 if (!getDerived().AlwaysRebuild() &&
10806 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10807 return E;
10808
10809 return getDerived().RebuildCXXFoldExpr(
10810 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10811 RHS.get(), E->getLocEnd());
10812 }
10813
10814 // The transform has determined that we should perform an elementwise
10815 // expansion of the pattern. Do so.
10816 ExprResult Result = getDerived().TransformExpr(E->getInit());
10817 if (Result.isInvalid())
10818 return true;
10819 bool LeftFold = E->isLeftFold();
10820
10821 // If we're retaining an expansion for a right fold, it is the innermost
10822 // component and takes the init (if any).
10823 if (!LeftFold && RetainExpansion) {
10824 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10825
10826 ExprResult Out = getDerived().TransformExpr(Pattern);
10827 if (Out.isInvalid())
10828 return true;
10829
10830 Result = getDerived().RebuildCXXFoldExpr(
10831 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10832 Result.get(), E->getLocEnd());
10833 if (Result.isInvalid())
10834 return true;
10835 }
10836
10837 for (unsigned I = 0; I != *NumExpansions; ++I) {
10838 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10839 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10840 ExprResult Out = getDerived().TransformExpr(Pattern);
10841 if (Out.isInvalid())
10842 return true;
10843
10844 if (Out.get()->containsUnexpandedParameterPack()) {
10845 // We still have a pack; retain a pack expansion for this slice.
10846 Result = getDerived().RebuildCXXFoldExpr(
10847 E->getLocStart(),
10848 LeftFold ? Result.get() : Out.get(),
10849 E->getOperator(), E->getEllipsisLoc(),
10850 LeftFold ? Out.get() : Result.get(),
10851 E->getLocEnd());
10852 } else if (Result.isUsable()) {
10853 // We've got down to a single element; build a binary operator.
10854 Result = getDerived().RebuildBinaryOperator(
10855 E->getEllipsisLoc(), E->getOperator(),
10856 LeftFold ? Result.get() : Out.get(),
10857 LeftFold ? Out.get() : Result.get());
10858 } else
10859 Result = Out;
10860
10861 if (Result.isInvalid())
10862 return true;
10863 }
10864
10865 // If we're retaining an expansion for a left fold, it is the outermost
10866 // component and takes the complete expansion so far as its init (if any).
10867 if (LeftFold && RetainExpansion) {
10868 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10869
10870 ExprResult Out = getDerived().TransformExpr(Pattern);
10871 if (Out.isInvalid())
10872 return true;
10873
10874 Result = getDerived().RebuildCXXFoldExpr(
10875 E->getLocStart(), Result.get(),
10876 E->getOperator(), E->getEllipsisLoc(),
10877 Out.get(), E->getLocEnd());
10878 if (Result.isInvalid())
10879 return true;
10880 }
10881
10882 // If we had no init and an empty pack, and we're not retaining an expansion,
10883 // then produce a fallback value or error.
10884 if (Result.isUnset())
10885 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10886 E->getOperator());
10887
10888 return Result;
10889}
10890
10891template<typename Derived>
10892ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010893TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10894 CXXStdInitializerListExpr *E) {
10895 return getDerived().TransformExpr(E->getSubExpr());
10896}
10897
10898template<typename Derived>
10899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010900TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010901 return SemaRef.MaybeBindToTemporary(E);
10902}
10903
10904template<typename Derived>
10905ExprResult
10906TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010907 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010908}
10909
10910template<typename Derived>
10911ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010912TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10913 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10914 if (SubExpr.isInvalid())
10915 return ExprError();
10916
10917 if (!getDerived().AlwaysRebuild() &&
10918 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010919 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010920
10921 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010922}
10923
10924template<typename Derived>
10925ExprResult
10926TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10927 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010928 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010929 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010930 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010931 /*IsCall=*/false, Elements, &ArgChanged))
10932 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010933
Ted Kremeneke65b0862012-03-06 20:05:56 +000010934 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10935 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010936
Ted Kremeneke65b0862012-03-06 20:05:56 +000010937 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10938 Elements.data(),
10939 Elements.size());
10940}
10941
10942template<typename Derived>
10943ExprResult
10944TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010945 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010946 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010947 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010948 bool ArgChanged = false;
10949 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10950 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010951
Ted Kremeneke65b0862012-03-06 20:05:56 +000010952 if (OrigElement.isPackExpansion()) {
10953 // This key/value element is a pack expansion.
10954 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10955 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10956 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10957 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10958
10959 // Determine whether the set of unexpanded parameter packs can
10960 // and should be expanded.
10961 bool Expand = true;
10962 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010963 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10964 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010965 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10966 OrigElement.Value->getLocEnd());
10967 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10968 PatternRange,
10969 Unexpanded,
10970 Expand, RetainExpansion,
10971 NumExpansions))
10972 return ExprError();
10973
10974 if (!Expand) {
10975 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010976 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010977 // expansion.
10978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10979 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10980 if (Key.isInvalid())
10981 return ExprError();
10982
10983 if (Key.get() != OrigElement.Key)
10984 ArgChanged = true;
10985
10986 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10987 if (Value.isInvalid())
10988 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010989
Ted Kremeneke65b0862012-03-06 20:05:56 +000010990 if (Value.get() != OrigElement.Value)
10991 ArgChanged = true;
10992
Chad Rosier1dcde962012-08-08 18:46:20 +000010993 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010994 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10995 };
10996 Elements.push_back(Expansion);
10997 continue;
10998 }
10999
11000 // Record right away that the argument was changed. This needs
11001 // to happen even if the array expands to nothing.
11002 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011003
Ted Kremeneke65b0862012-03-06 20:05:56 +000011004 // The transform has determined that we should perform an elementwise
11005 // expansion of the pattern. Do so.
11006 for (unsigned I = 0; I != *NumExpansions; ++I) {
11007 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11008 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11009 if (Key.isInvalid())
11010 return ExprError();
11011
11012 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11013 if (Value.isInvalid())
11014 return ExprError();
11015
Chad Rosier1dcde962012-08-08 18:46:20 +000011016 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011017 Key.get(), Value.get(), SourceLocation(), NumExpansions
11018 };
11019
11020 // If any unexpanded parameter packs remain, we still have a
11021 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011022 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011023 if (Key.get()->containsUnexpandedParameterPack() ||
11024 Value.get()->containsUnexpandedParameterPack())
11025 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011026
Ted Kremeneke65b0862012-03-06 20:05:56 +000011027 Elements.push_back(Element);
11028 }
11029
Richard Smith9467be42014-06-06 17:33:35 +000011030 // FIXME: Retain a pack expansion if RetainExpansion is true.
11031
Ted Kremeneke65b0862012-03-06 20:05:56 +000011032 // We've finished with this pack expansion.
11033 continue;
11034 }
11035
11036 // Transform and check key.
11037 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11038 if (Key.isInvalid())
11039 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011040
Ted Kremeneke65b0862012-03-06 20:05:56 +000011041 if (Key.get() != OrigElement.Key)
11042 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011043
Ted Kremeneke65b0862012-03-06 20:05:56 +000011044 // Transform and check value.
11045 ExprResult Value
11046 = getDerived().TransformExpr(OrigElement.Value);
11047 if (Value.isInvalid())
11048 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011049
Ted Kremeneke65b0862012-03-06 20:05:56 +000011050 if (Value.get() != OrigElement.Value)
11051 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011052
11053 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011054 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011055 };
11056 Elements.push_back(Element);
11057 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011058
Ted Kremeneke65b0862012-03-06 20:05:56 +000011059 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11060 return SemaRef.MaybeBindToTemporary(E);
11061
11062 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011063 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011064}
11065
Mike Stump11289f42009-09-09 15:08:12 +000011066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011068TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011069 TypeSourceInfo *EncodedTypeInfo
11070 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11071 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011073
Douglas Gregora16548e2009-08-11 05:31:07 +000011074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011075 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011076 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011077
11078 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011079 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011080 E->getRParenLoc());
11081}
Mike Stump11289f42009-09-09 15:08:12 +000011082
Douglas Gregora16548e2009-08-11 05:31:07 +000011083template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011084ExprResult TreeTransform<Derived>::
11085TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011086 // This is a kind of implicit conversion, and it needs to get dropped
11087 // and recomputed for the same general reasons that ImplicitCastExprs
11088 // do, as well a more specific one: this expression is only valid when
11089 // it appears *immediately* as an argument expression.
11090 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011091}
11092
11093template<typename Derived>
11094ExprResult TreeTransform<Derived>::
11095TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011096 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011097 = getDerived().TransformType(E->getTypeInfoAsWritten());
11098 if (!TSInfo)
11099 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011100
John McCall31168b02011-06-15 23:02:42 +000011101 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011102 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011103 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011104
John McCall31168b02011-06-15 23:02:42 +000011105 if (!getDerived().AlwaysRebuild() &&
11106 TSInfo == E->getTypeInfoAsWritten() &&
11107 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011108 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011109
John McCall31168b02011-06-15 23:02:42 +000011110 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011111 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011112 Result.get());
11113}
11114
11115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011117TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011118 // Transform arguments.
11119 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011120 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011121 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011122 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011123 &ArgChanged))
11124 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011125
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011126 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11127 // Class message: transform the receiver type.
11128 TypeSourceInfo *ReceiverTypeInfo
11129 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11130 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011131 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011132
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011133 // If nothing changed, just retain the existing message send.
11134 if (!getDerived().AlwaysRebuild() &&
11135 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011136 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011137
11138 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011139 SmallVector<SourceLocation, 16> SelLocs;
11140 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011141 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11142 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011143 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011144 E->getMethodDecl(),
11145 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011146 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011147 E->getRightLoc());
11148 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011149 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11150 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11151 // Build a new class message send to 'super'.
11152 SmallVector<SourceLocation, 16> SelLocs;
11153 E->getSelectorLocs(SelLocs);
11154 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11155 E->getSelector(),
11156 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011157 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011158 E->getMethodDecl(),
11159 E->getLeftLoc(),
11160 Args,
11161 E->getRightLoc());
11162 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011163
11164 // Instance message: transform the receiver
11165 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11166 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011167 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011168 = getDerived().TransformExpr(E->getInstanceReceiver());
11169 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011170 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011171
11172 // If nothing changed, just retain the existing message send.
11173 if (!getDerived().AlwaysRebuild() &&
11174 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011175 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011176
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011177 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011178 SmallVector<SourceLocation, 16> SelLocs;
11179 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011180 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011181 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011182 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011183 E->getMethodDecl(),
11184 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011185 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011186 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011187}
11188
Mike Stump11289f42009-09-09 15:08:12 +000011189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011191TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011192 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011193}
11194
Mike Stump11289f42009-09-09 15:08:12 +000011195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011196ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011197TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011198 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011199}
11200
Mike Stump11289f42009-09-09 15:08:12 +000011201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011203TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011204 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011205 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011206 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011207 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011208
11209 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011210
Douglas Gregord51d90d2010-04-26 20:11:03 +000011211 // If nothing changed, just retain the existing expression.
11212 if (!getDerived().AlwaysRebuild() &&
11213 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011214 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011215
John McCallb268a282010-08-23 23:25:46 +000011216 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011217 E->getLocation(),
11218 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011219}
11220
Mike Stump11289f42009-09-09 15:08:12 +000011221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011223TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011224 // 'super' and types never change. Property never changes. Just
11225 // retain the existing expression.
11226 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011227 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011228
Douglas Gregor9faee212010-04-26 20:47:02 +000011229 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011230 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011231 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011232 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011233
Douglas Gregor9faee212010-04-26 20:47:02 +000011234 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011235
Douglas Gregor9faee212010-04-26 20:47:02 +000011236 // If nothing changed, just retain the existing expression.
11237 if (!getDerived().AlwaysRebuild() &&
11238 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011239 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011240
John McCallb7bd14f2010-12-02 01:19:52 +000011241 if (E->isExplicitProperty())
11242 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11243 E->getExplicitProperty(),
11244 E->getLocation());
11245
11246 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011247 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011248 E->getImplicitPropertyGetter(),
11249 E->getImplicitPropertySetter(),
11250 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011251}
11252
Mike Stump11289f42009-09-09 15:08:12 +000011253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011254ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011255TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11256 // Transform the base expression.
11257 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11258 if (Base.isInvalid())
11259 return ExprError();
11260
11261 // Transform the key expression.
11262 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11263 if (Key.isInvalid())
11264 return ExprError();
11265
11266 // If nothing changed, just retain the existing expression.
11267 if (!getDerived().AlwaysRebuild() &&
11268 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011269 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011270
Chad Rosier1dcde962012-08-08 18:46:20 +000011271 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011272 Base.get(), Key.get(),
11273 E->getAtIndexMethodDecl(),
11274 E->setAtIndexMethodDecl());
11275}
11276
11277template<typename Derived>
11278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011279TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011280 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011281 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011282 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011283 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011284
Douglas Gregord51d90d2010-04-26 20:11:03 +000011285 // If nothing changed, just retain the existing expression.
11286 if (!getDerived().AlwaysRebuild() &&
11287 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011288 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011289
John McCallb268a282010-08-23 23:25:46 +000011290 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011291 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011292 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011293}
11294
Mike Stump11289f42009-09-09 15:08:12 +000011295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011297TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011298 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011299 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011300 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011301 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011302 SubExprs, &ArgumentChanged))
11303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011304
Douglas Gregora16548e2009-08-11 05:31:07 +000011305 if (!getDerived().AlwaysRebuild() &&
11306 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011307 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011308
Douglas Gregora16548e2009-08-11 05:31:07 +000011309 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011310 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011311 E->getRParenLoc());
11312}
11313
Mike Stump11289f42009-09-09 15:08:12 +000011314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011315ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011316TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11317 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11318 if (SrcExpr.isInvalid())
11319 return ExprError();
11320
11321 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11322 if (!Type)
11323 return ExprError();
11324
11325 if (!getDerived().AlwaysRebuild() &&
11326 Type == E->getTypeSourceInfo() &&
11327 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011328 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011329
11330 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11331 SrcExpr.get(), Type,
11332 E->getRParenLoc());
11333}
11334
11335template<typename Derived>
11336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011337TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011338 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011339
Craig Topperc3ec1492014-05-26 06:22:03 +000011340 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011341 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11342
11343 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011344 blockScope->TheDecl->setBlockMissingReturnType(
11345 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011346
Chris Lattner01cf8db2011-07-20 06:58:45 +000011347 SmallVector<ParmVarDecl*, 4> params;
11348 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011349
John McCallc8e321d2016-03-01 02:09:25 +000011350 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11351
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011352 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011353 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011354 if (getDerived().TransformFunctionTypeParams(
11355 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11356 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11357 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011358 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011359 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011360 }
John McCall490112f2011-02-04 18:33:18 +000011361
Eli Friedman34b49062012-01-26 03:00:14 +000011362 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011363 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011364
John McCallc8e321d2016-03-01 02:09:25 +000011365 auto epi = exprFunctionType->getExtProtoInfo();
11366 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11367
Jordan Rose5c382722013-03-08 21:51:21 +000011368 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011369 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011370 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011371
11372 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011373 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011374 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011375
11376 if (!oldBlock->blockMissingReturnType()) {
11377 blockScope->HasImplicitReturnType = false;
11378 blockScope->ReturnType = exprResultType;
11379 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011380
John McCall3882ace2011-01-05 12:14:39 +000011381 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011382 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011383 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011384 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011385 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011386 }
John McCall3882ace2011-01-05 12:14:39 +000011387
John McCall490112f2011-02-04 18:33:18 +000011388#ifndef NDEBUG
11389 // In builds with assertions, make sure that we captured everything we
11390 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011391 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011392 for (const auto &I : oldBlock->captures()) {
11393 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011394
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011395 // Ignore parameter packs.
11396 if (isa<ParmVarDecl>(oldCapture) &&
11397 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11398 continue;
John McCall490112f2011-02-04 18:33:18 +000011399
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011400 VarDecl *newCapture =
11401 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11402 oldCapture));
11403 assert(blockScope->CaptureMap.count(newCapture));
11404 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011405 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011406 }
11407#endif
11408
11409 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011410 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011411}
11412
Mike Stump11289f42009-09-09 15:08:12 +000011413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011414ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011415TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011416 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011417}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011418
11419template<typename Derived>
11420ExprResult
11421TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011422 QualType RetTy = getDerived().TransformType(E->getType());
11423 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011424 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011425 SubExprs.reserve(E->getNumSubExprs());
11426 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11427 SubExprs, &ArgumentChanged))
11428 return ExprError();
11429
11430 if (!getDerived().AlwaysRebuild() &&
11431 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011432 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011433
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011434 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011435 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011436}
Chad Rosier1dcde962012-08-08 18:46:20 +000011437
Douglas Gregora16548e2009-08-11 05:31:07 +000011438//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011439// Type reconstruction
11440//===----------------------------------------------------------------------===//
11441
Mike Stump11289f42009-09-09 15:08:12 +000011442template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011443QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11444 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011445 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011446 getDerived().getBaseEntity());
11447}
11448
Mike Stump11289f42009-09-09 15:08:12 +000011449template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011450QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11451 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011452 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011453 getDerived().getBaseEntity());
11454}
11455
Mike Stump11289f42009-09-09 15:08:12 +000011456template<typename Derived>
11457QualType
John McCall70dd5f62009-10-30 00:06:24 +000011458TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11459 bool WrittenAsLValue,
11460 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011461 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011462 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011463}
11464
11465template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011466QualType
John McCall70dd5f62009-10-30 00:06:24 +000011467TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11468 QualType ClassType,
11469 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011470 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11471 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011472}
11473
11474template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011475QualType TreeTransform<Derived>::RebuildObjCObjectType(
11476 QualType BaseType,
11477 SourceLocation Loc,
11478 SourceLocation TypeArgsLAngleLoc,
11479 ArrayRef<TypeSourceInfo *> TypeArgs,
11480 SourceLocation TypeArgsRAngleLoc,
11481 SourceLocation ProtocolLAngleLoc,
11482 ArrayRef<ObjCProtocolDecl *> Protocols,
11483 ArrayRef<SourceLocation> ProtocolLocs,
11484 SourceLocation ProtocolRAngleLoc) {
11485 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11486 TypeArgs, TypeArgsRAngleLoc,
11487 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11488 ProtocolRAngleLoc,
11489 /*FailOnError=*/true);
11490}
11491
11492template<typename Derived>
11493QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11494 QualType PointeeType,
11495 SourceLocation Star) {
11496 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11497}
11498
11499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011500QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011501TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11502 ArrayType::ArraySizeModifier SizeMod,
11503 const llvm::APInt *Size,
11504 Expr *SizeExpr,
11505 unsigned IndexTypeQuals,
11506 SourceRange BracketsRange) {
11507 if (SizeExpr || !Size)
11508 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11509 IndexTypeQuals, BracketsRange,
11510 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011511
11512 QualType Types[] = {
11513 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11514 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11515 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011516 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011517 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011518 QualType SizeType;
11519 for (unsigned I = 0; I != NumTypes; ++I)
11520 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11521 SizeType = Types[I];
11522 break;
11523 }
Mike Stump11289f42009-09-09 15:08:12 +000011524
Eli Friedman9562f392012-01-25 23:20:27 +000011525 // Note that we can return a VariableArrayType here in the case where
11526 // the element type was a dependent VariableArrayType.
11527 IntegerLiteral *ArraySize
11528 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11529 /*FIXME*/BracketsRange.getBegin());
11530 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011531 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011532 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011533}
Mike Stump11289f42009-09-09 15:08:12 +000011534
Douglas Gregord6ff3322009-08-04 16:50:30 +000011535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011536QualType
11537TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011538 ArrayType::ArraySizeModifier SizeMod,
11539 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011540 unsigned IndexTypeQuals,
11541 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011542 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011543 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011544}
11545
11546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011547QualType
Mike Stump11289f42009-09-09 15:08:12 +000011548TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011549 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011550 unsigned IndexTypeQuals,
11551 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011552 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011553 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011554}
Mike Stump11289f42009-09-09 15:08:12 +000011555
Douglas Gregord6ff3322009-08-04 16:50:30 +000011556template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011557QualType
11558TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011559 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011560 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011561 unsigned IndexTypeQuals,
11562 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011563 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011564 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011565 IndexTypeQuals, BracketsRange);
11566}
11567
11568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011569QualType
11570TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011571 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011572 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011573 unsigned IndexTypeQuals,
11574 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011575 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011576 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011577 IndexTypeQuals, BracketsRange);
11578}
11579
11580template<typename Derived>
11581QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011582 unsigned NumElements,
11583 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011584 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011585 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011586}
Mike Stump11289f42009-09-09 15:08:12 +000011587
Douglas Gregord6ff3322009-08-04 16:50:30 +000011588template<typename Derived>
11589QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11590 unsigned NumElements,
11591 SourceLocation AttributeLoc) {
11592 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11593 NumElements, true);
11594 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011595 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11596 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011597 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011598}
Mike Stump11289f42009-09-09 15:08:12 +000011599
Douglas Gregord6ff3322009-08-04 16:50:30 +000011600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011601QualType
11602TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011603 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011604 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011605 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011606}
Mike Stump11289f42009-09-09 15:08:12 +000011607
Douglas Gregord6ff3322009-08-04 16:50:30 +000011608template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011609QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11610 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011611 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011612 const FunctionProtoType::ExtProtoInfo &EPI) {
11613 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011614 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011615 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011616 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011617}
Mike Stump11289f42009-09-09 15:08:12 +000011618
Douglas Gregord6ff3322009-08-04 16:50:30 +000011619template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011620QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11621 return SemaRef.Context.getFunctionNoProtoType(T);
11622}
11623
11624template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011625QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11626 assert(D && "no decl found");
11627 if (D->isInvalidDecl()) return QualType();
11628
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011629 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011630 TypeDecl *Ty;
11631 if (isa<UsingDecl>(D)) {
11632 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011633 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011634 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11635
11636 // A valid resolved using typename decl points to exactly one type decl.
11637 assert(++Using->shadow_begin() == Using->shadow_end());
11638 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011639
John McCallb96ec562009-12-04 22:46:56 +000011640 } else {
11641 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11642 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11643 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11644 }
11645
11646 return SemaRef.Context.getTypeDeclType(Ty);
11647}
11648
11649template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011650QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11651 SourceLocation Loc) {
11652 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011653}
11654
11655template<typename Derived>
11656QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11657 return SemaRef.Context.getTypeOfType(Underlying);
11658}
11659
11660template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011661QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11662 SourceLocation Loc) {
11663 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011664}
11665
11666template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011667QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11668 UnaryTransformType::UTTKind UKind,
11669 SourceLocation Loc) {
11670 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11671}
11672
11673template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011674QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011675 TemplateName Template,
11676 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011677 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011678 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011679}
Mike Stump11289f42009-09-09 15:08:12 +000011680
Douglas Gregor1135c352009-08-06 05:28:30 +000011681template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011682QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11683 SourceLocation KWLoc) {
11684 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11685}
11686
11687template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011688QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11689 SourceLocation KWLoc) {
11690 return SemaRef.BuildPipeType(ValueType, KWLoc);
11691}
11692
11693template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011694TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011695TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011696 bool TemplateKW,
11697 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011698 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011699 Template);
11700}
11701
11702template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011703TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011704TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11705 const IdentifierInfo &Name,
11706 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011707 QualType ObjectType,
11708 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011709 UnqualifiedId TemplateName;
11710 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011711 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011712 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011713 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011714 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011715 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011716 /*EnteringContext=*/false,
11717 Template);
John McCall31f82722010-11-12 08:19:04 +000011718 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011719}
Mike Stump11289f42009-09-09 15:08:12 +000011720
Douglas Gregora16548e2009-08-11 05:31:07 +000011721template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011722TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011723TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011724 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011725 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011726 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011727 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011728 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011729 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011730 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011731 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011732 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011733 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011734 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011735 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011736 /*EnteringContext=*/false,
11737 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011738 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011739}
Chad Rosier1dcde962012-08-08 18:46:20 +000011740
Douglas Gregor71395fa2009-11-04 00:56:37 +000011741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011742ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011743TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11744 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011745 Expr *OrigCallee,
11746 Expr *First,
11747 Expr *Second) {
11748 Expr *Callee = OrigCallee->IgnoreParenCasts();
11749 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011750
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011751 if (First->getObjectKind() == OK_ObjCProperty) {
11752 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11753 if (BinaryOperator::isAssignmentOp(Opc))
11754 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11755 First, Second);
11756 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11757 if (Result.isInvalid())
11758 return ExprError();
11759 First = Result.get();
11760 }
11761
11762 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11763 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11764 if (Result.isInvalid())
11765 return ExprError();
11766 Second = Result.get();
11767 }
11768
Douglas Gregora16548e2009-08-11 05:31:07 +000011769 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011770 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011771 if (!First->getType()->isOverloadableType() &&
11772 !Second->getType()->isOverloadableType())
11773 return getSema().CreateBuiltinArraySubscriptExpr(First,
11774 Callee->getLocStart(),
11775 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011776 } else if (Op == OO_Arrow) {
11777 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011778 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11779 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011780 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011781 // The argument is not of overloadable type, so try to create a
11782 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011783 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011784 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011785
John McCallb268a282010-08-23 23:25:46 +000011786 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011787 }
11788 } else {
John McCallb268a282010-08-23 23:25:46 +000011789 if (!First->getType()->isOverloadableType() &&
11790 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011791 // Neither of the arguments is an overloadable type, so try to
11792 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011793 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011794 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011795 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011796 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011798
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011799 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011800 }
11801 }
Mike Stump11289f42009-09-09 15:08:12 +000011802
11803 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011804 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011805 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011806
John McCallb268a282010-08-23 23:25:46 +000011807 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011808 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011809 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011810 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011811 // If we've resolved this to a particular non-member function, just call
11812 // that function. If we resolved it to a member function,
11813 // CreateOverloaded* will find that function for us.
11814 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11815 if (!isa<CXXMethodDecl>(ND))
11816 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011817 }
Mike Stump11289f42009-09-09 15:08:12 +000011818
Douglas Gregora16548e2009-08-11 05:31:07 +000011819 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011820 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011821 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011822
Douglas Gregora16548e2009-08-11 05:31:07 +000011823 // Create the overloaded operator invocation for unary operators.
11824 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011825 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011826 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011827 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011828 }
Mike Stump11289f42009-09-09 15:08:12 +000011829
Douglas Gregore9d62932011-07-15 16:25:15 +000011830 if (Op == OO_Subscript) {
11831 SourceLocation LBrace;
11832 SourceLocation RBrace;
11833
11834 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011835 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011836 LBrace = SourceLocation::getFromRawEncoding(
11837 NameLoc.CXXOperatorName.BeginOpNameLoc);
11838 RBrace = SourceLocation::getFromRawEncoding(
11839 NameLoc.CXXOperatorName.EndOpNameLoc);
11840 } else {
11841 LBrace = Callee->getLocStart();
11842 RBrace = OpLoc;
11843 }
11844
11845 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11846 First, Second);
11847 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011848
Douglas Gregora16548e2009-08-11 05:31:07 +000011849 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011850 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011851 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011852 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11853 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011855
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011856 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011857}
Mike Stump11289f42009-09-09 15:08:12 +000011858
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011859template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011860ExprResult
John McCallb268a282010-08-23 23:25:46 +000011861TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011862 SourceLocation OperatorLoc,
11863 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011864 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011865 TypeSourceInfo *ScopeType,
11866 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011867 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011868 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011869 QualType BaseType = Base->getType();
11870 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011871 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011872 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011873 !BaseType->getAs<PointerType>()->getPointeeType()
11874 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011875 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011876 return SemaRef.BuildPseudoDestructorExpr(
11877 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11878 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011879 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011880
Douglas Gregor678f90d2010-02-25 01:56:36 +000011881 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011882 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11883 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11884 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11885 NameInfo.setNamedTypeInfo(DestroyedType);
11886
Richard Smith8e4a3862012-05-15 06:15:11 +000011887 // The scope type is now known to be a valid nested name specifier
11888 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011889 if (ScopeType) {
11890 if (!ScopeType->getType()->getAs<TagType>()) {
11891 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11892 diag::err_expected_class_or_namespace)
11893 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11894 return ExprError();
11895 }
11896 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11897 CCLoc);
11898 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011899
Abramo Bagnara7945c982012-01-27 09:46:47 +000011900 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011901 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011902 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011903 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011904 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011905 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011906 /*TemplateArgs*/ nullptr,
11907 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011908}
11909
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011910template<typename Derived>
11911StmtResult
11912TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011913 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011914 CapturedDecl *CD = S->getCapturedDecl();
11915 unsigned NumParams = CD->getNumParams();
11916 unsigned ContextParamPos = CD->getContextParamPosition();
11917 SmallVector<Sema::CapturedParamNameType, 4> Params;
11918 for (unsigned I = 0; I < NumParams; ++I) {
11919 if (I != ContextParamPos) {
11920 Params.push_back(
11921 std::make_pair(
11922 CD->getParam(I)->getName(),
11923 getDerived().TransformType(CD->getParam(I)->getType())));
11924 } else {
11925 Params.push_back(std::make_pair(StringRef(), QualType()));
11926 }
11927 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011928 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011929 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011930 StmtResult Body;
11931 {
11932 Sema::CompoundScopeRAII CompoundScope(getSema());
11933 Body = getDerived().TransformStmt(S->getCapturedStmt());
11934 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011935
11936 if (Body.isInvalid()) {
11937 getSema().ActOnCapturedRegionError();
11938 return StmtError();
11939 }
11940
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011941 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011942}
11943
Douglas Gregord6ff3322009-08-04 16:50:30 +000011944} // end namespace clang
11945
Hans Wennborg59dbe862015-09-29 20:56:43 +000011946#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H