blob: 9c55478ca8d9245938f9c06e033327d72f8c7360 [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
Kelvin Li986330c2016-07-20 22:57:10 +00007629template <typename Derived>
7630StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7631 OMPTargetSimdDirective *D) {
7632 DeclarationNameInfo DirName;
7633 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7634 D->getLocStart());
7635 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7636 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7637 return Res;
7638}
7639
Alexander Musman64d33f12014-06-04 07:53:32 +00007640//===----------------------------------------------------------------------===//
7641// OpenMP clause transformation
7642//===----------------------------------------------------------------------===//
7643template <typename Derived>
7644OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007645 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7646 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007647 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007648 return getDerived().RebuildOMPIfClause(
7649 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7650 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007651}
7652
Alexander Musman64d33f12014-06-04 07:53:32 +00007653template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007654OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7655 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7656 if (Cond.isInvalid())
7657 return nullptr;
7658 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7659 C->getLParenLoc(), C->getLocEnd());
7660}
7661
7662template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007663OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007664TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7665 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7666 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007667 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007668 return getDerived().RebuildOMPNumThreadsClause(
7669 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007670}
7671
Alexey Bataev62c87d22014-03-21 04:51:18 +00007672template <typename Derived>
7673OMPClause *
7674TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7675 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7676 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007677 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007678 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007679 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007680}
7681
Alexander Musman8bd31e62014-05-27 15:12:19 +00007682template <typename Derived>
7683OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007684TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7685 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7686 if (E.isInvalid())
7687 return nullptr;
7688 return getDerived().RebuildOMPSimdlenClause(
7689 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7690}
7691
7692template <typename Derived>
7693OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007694TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7695 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7696 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007697 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007698 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007699 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007700}
7701
Alexander Musman64d33f12014-06-04 07:53:32 +00007702template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007703OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007704TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007705 return getDerived().RebuildOMPDefaultClause(
7706 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7707 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007708}
7709
Alexander Musman64d33f12014-06-04 07:53:32 +00007710template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007711OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007712TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007713 return getDerived().RebuildOMPProcBindClause(
7714 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7715 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007716}
7717
Alexander Musman64d33f12014-06-04 07:53:32 +00007718template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007719OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007720TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7721 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7722 if (E.isInvalid())
7723 return nullptr;
7724 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007725 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007726 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007727 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007728 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7729}
7730
7731template <typename Derived>
7732OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007733TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007734 ExprResult E;
7735 if (auto *Num = C->getNumForLoops()) {
7736 E = getDerived().TransformExpr(Num);
7737 if (E.isInvalid())
7738 return nullptr;
7739 }
7740 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7741 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007742}
7743
7744template <typename Derived>
7745OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007746TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7747 // No need to rebuild this clause, no template-dependent parameters.
7748 return C;
7749}
7750
7751template <typename Derived>
7752OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007753TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7754 // No need to rebuild this clause, no template-dependent parameters.
7755 return C;
7756}
7757
7758template <typename Derived>
7759OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007760TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7761 // No need to rebuild this clause, no template-dependent parameters.
7762 return C;
7763}
7764
7765template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007766OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7767 // No need to rebuild this clause, no template-dependent parameters.
7768 return C;
7769}
7770
7771template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007772OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7773 // No need to rebuild this clause, no template-dependent parameters.
7774 return C;
7775}
7776
7777template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007778OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007779TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7780 // No need to rebuild this clause, no template-dependent parameters.
7781 return C;
7782}
7783
7784template <typename Derived>
7785OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007786TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7787 // No need to rebuild this clause, no template-dependent parameters.
7788 return C;
7789}
7790
7791template <typename Derived>
7792OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007793TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7794 // No need to rebuild this clause, no template-dependent parameters.
7795 return C;
7796}
7797
7798template <typename Derived>
7799OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007800TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7801 // No need to rebuild this clause, no template-dependent parameters.
7802 return C;
7803}
7804
7805template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007806OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7807 // No need to rebuild this clause, no template-dependent parameters.
7808 return C;
7809}
7810
7811template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007812OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007813TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7814 // No need to rebuild this clause, no template-dependent parameters.
7815 return C;
7816}
7817
7818template <typename Derived>
7819OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007820TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007821 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007822 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007823 for (auto *VE : C->varlists()) {
7824 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007825 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007826 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007827 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007828 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007829 return getDerived().RebuildOMPPrivateClause(
7830 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007831}
7832
Alexander Musman64d33f12014-06-04 07:53:32 +00007833template <typename Derived>
7834OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7835 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007836 llvm::SmallVector<Expr *, 16> Vars;
7837 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007838 for (auto *VE : C->varlists()) {
7839 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007840 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007841 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007842 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007843 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007844 return getDerived().RebuildOMPFirstprivateClause(
7845 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007846}
7847
Alexander Musman64d33f12014-06-04 07:53:32 +00007848template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007849OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007850TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7851 llvm::SmallVector<Expr *, 16> Vars;
7852 Vars.reserve(C->varlist_size());
7853 for (auto *VE : C->varlists()) {
7854 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7855 if (EVar.isInvalid())
7856 return nullptr;
7857 Vars.push_back(EVar.get());
7858 }
7859 return getDerived().RebuildOMPLastprivateClause(
7860 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7861}
7862
7863template <typename Derived>
7864OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007865TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7866 llvm::SmallVector<Expr *, 16> Vars;
7867 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007868 for (auto *VE : C->varlists()) {
7869 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007870 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007871 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007872 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007873 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007874 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7875 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007876}
7877
Alexander Musman64d33f12014-06-04 07:53:32 +00007878template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007879OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007880TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7881 llvm::SmallVector<Expr *, 16> Vars;
7882 Vars.reserve(C->varlist_size());
7883 for (auto *VE : C->varlists()) {
7884 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7885 if (EVar.isInvalid())
7886 return nullptr;
7887 Vars.push_back(EVar.get());
7888 }
7889 CXXScopeSpec ReductionIdScopeSpec;
7890 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7891
7892 DeclarationNameInfo NameInfo = C->getNameInfo();
7893 if (NameInfo.getName()) {
7894 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7895 if (!NameInfo.getName())
7896 return nullptr;
7897 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007898 // Build a list of all UDR decls with the same names ranged by the Scopes.
7899 // The Scope boundary is a duplication of the previous decl.
7900 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7901 for (auto *E : C->reduction_ops()) {
7902 // Transform all the decls.
7903 if (E) {
7904 auto *ULE = cast<UnresolvedLookupExpr>(E);
7905 UnresolvedSet<8> Decls;
7906 for (auto *D : ULE->decls()) {
7907 NamedDecl *InstD =
7908 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7909 Decls.addDecl(InstD, InstD->getAccess());
7910 }
7911 UnresolvedReductions.push_back(
7912 UnresolvedLookupExpr::Create(
7913 SemaRef.Context, /*NamingClass=*/nullptr,
7914 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7915 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7916 Decls.begin(), Decls.end()));
7917 } else
7918 UnresolvedReductions.push_back(nullptr);
7919 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007920 return getDerived().RebuildOMPReductionClause(
7921 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007922 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007923}
7924
7925template <typename Derived>
7926OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007927TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7928 llvm::SmallVector<Expr *, 16> Vars;
7929 Vars.reserve(C->varlist_size());
7930 for (auto *VE : C->varlists()) {
7931 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7932 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007933 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007934 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007935 }
7936 ExprResult Step = getDerived().TransformExpr(C->getStep());
7937 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007938 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007939 return getDerived().RebuildOMPLinearClause(
7940 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7941 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007942}
7943
Alexander Musman64d33f12014-06-04 07:53:32 +00007944template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007945OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007946TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7947 llvm::SmallVector<Expr *, 16> Vars;
7948 Vars.reserve(C->varlist_size());
7949 for (auto *VE : C->varlists()) {
7950 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7951 if (EVar.isInvalid())
7952 return nullptr;
7953 Vars.push_back(EVar.get());
7954 }
7955 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7956 if (Alignment.isInvalid())
7957 return nullptr;
7958 return getDerived().RebuildOMPAlignedClause(
7959 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7960 C->getColonLoc(), C->getLocEnd());
7961}
7962
Alexander Musman64d33f12014-06-04 07:53:32 +00007963template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007964OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007965TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7966 llvm::SmallVector<Expr *, 16> Vars;
7967 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007968 for (auto *VE : C->varlists()) {
7969 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007970 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007971 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007972 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007973 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007974 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7975 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007976}
7977
Alexey Bataevbae9a792014-06-27 10:37:06 +00007978template <typename Derived>
7979OMPClause *
7980TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7981 llvm::SmallVector<Expr *, 16> Vars;
7982 Vars.reserve(C->varlist_size());
7983 for (auto *VE : C->varlists()) {
7984 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7985 if (EVar.isInvalid())
7986 return nullptr;
7987 Vars.push_back(EVar.get());
7988 }
7989 return getDerived().RebuildOMPCopyprivateClause(
7990 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7991}
7992
Alexey Bataev6125da92014-07-21 11:26:11 +00007993template <typename Derived>
7994OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7995 llvm::SmallVector<Expr *, 16> Vars;
7996 Vars.reserve(C->varlist_size());
7997 for (auto *VE : C->varlists()) {
7998 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7999 if (EVar.isInvalid())
8000 return nullptr;
8001 Vars.push_back(EVar.get());
8002 }
8003 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8004 C->getLParenLoc(), C->getLocEnd());
8005}
8006
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008007template <typename Derived>
8008OMPClause *
8009TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8010 llvm::SmallVector<Expr *, 16> Vars;
8011 Vars.reserve(C->varlist_size());
8012 for (auto *VE : C->varlists()) {
8013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8014 if (EVar.isInvalid())
8015 return nullptr;
8016 Vars.push_back(EVar.get());
8017 }
8018 return getDerived().RebuildOMPDependClause(
8019 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8020 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8021}
8022
Michael Wonge710d542015-08-07 16:16:36 +00008023template <typename Derived>
8024OMPClause *
8025TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8026 ExprResult E = getDerived().TransformExpr(C->getDevice());
8027 if (E.isInvalid())
8028 return nullptr;
8029 return getDerived().RebuildOMPDeviceClause(
8030 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8031}
8032
Kelvin Li0bff7af2015-11-23 05:32:03 +00008033template <typename Derived>
8034OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8035 llvm::SmallVector<Expr *, 16> Vars;
8036 Vars.reserve(C->varlist_size());
8037 for (auto *VE : C->varlists()) {
8038 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8039 if (EVar.isInvalid())
8040 return nullptr;
8041 Vars.push_back(EVar.get());
8042 }
8043 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008044 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8045 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8046 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008047}
8048
Kelvin Li099bb8c2015-11-24 20:50:12 +00008049template <typename Derived>
8050OMPClause *
8051TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8052 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8053 if (E.isInvalid())
8054 return nullptr;
8055 return getDerived().RebuildOMPNumTeamsClause(
8056 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8057}
8058
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008059template <typename Derived>
8060OMPClause *
8061TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8062 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8063 if (E.isInvalid())
8064 return nullptr;
8065 return getDerived().RebuildOMPThreadLimitClause(
8066 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8067}
8068
Alexey Bataeva0569352015-12-01 10:17:31 +00008069template <typename Derived>
8070OMPClause *
8071TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8072 ExprResult E = getDerived().TransformExpr(C->getPriority());
8073 if (E.isInvalid())
8074 return nullptr;
8075 return getDerived().RebuildOMPPriorityClause(
8076 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8077}
8078
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008079template <typename Derived>
8080OMPClause *
8081TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8082 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8083 if (E.isInvalid())
8084 return nullptr;
8085 return getDerived().RebuildOMPGrainsizeClause(
8086 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8087}
8088
Alexey Bataev382967a2015-12-08 12:06:20 +00008089template <typename Derived>
8090OMPClause *
8091TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8092 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8093 if (E.isInvalid())
8094 return nullptr;
8095 return getDerived().RebuildOMPNumTasksClause(
8096 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8097}
8098
Alexey Bataev28c75412015-12-15 08:19:24 +00008099template <typename Derived>
8100OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8101 ExprResult E = getDerived().TransformExpr(C->getHint());
8102 if (E.isInvalid())
8103 return nullptr;
8104 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8105 C->getLParenLoc(), C->getLocEnd());
8106}
8107
Carlo Bertollib4adf552016-01-15 18:50:31 +00008108template <typename Derived>
8109OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8110 OMPDistScheduleClause *C) {
8111 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8112 if (E.isInvalid())
8113 return nullptr;
8114 return getDerived().RebuildOMPDistScheduleClause(
8115 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8116 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8117}
8118
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008119template <typename Derived>
8120OMPClause *
8121TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8122 return C;
8123}
8124
Samuel Antao661c0902016-05-26 17:39:58 +00008125template <typename Derived>
8126OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8127 llvm::SmallVector<Expr *, 16> Vars;
8128 Vars.reserve(C->varlist_size());
8129 for (auto *VE : C->varlists()) {
8130 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8131 if (EVar.isInvalid())
8132 return 0;
8133 Vars.push_back(EVar.get());
8134 }
8135 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8136 C->getLParenLoc(), C->getLocEnd());
8137}
8138
Samuel Antaoec172c62016-05-26 17:49:04 +00008139template <typename Derived>
8140OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8141 llvm::SmallVector<Expr *, 16> Vars;
8142 Vars.reserve(C->varlist_size());
8143 for (auto *VE : C->varlists()) {
8144 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8145 if (EVar.isInvalid())
8146 return 0;
8147 Vars.push_back(EVar.get());
8148 }
8149 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8150 C->getLParenLoc(), C->getLocEnd());
8151}
8152
Carlo Bertolli2404b172016-07-13 15:37:16 +00008153template <typename Derived>
8154OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8155 OMPUseDevicePtrClause *C) {
8156 llvm::SmallVector<Expr *, 16> Vars;
8157 Vars.reserve(C->varlist_size());
8158 for (auto *VE : C->varlists()) {
8159 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8160 if (EVar.isInvalid())
8161 return nullptr;
8162 Vars.push_back(EVar.get());
8163 }
8164 return getDerived().RebuildOMPUseDevicePtrClause(
8165 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8166}
8167
Carlo Bertolli70594e92016-07-13 17:16:49 +00008168template <typename Derived>
8169OMPClause *
8170TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8171 llvm::SmallVector<Expr *, 16> Vars;
8172 Vars.reserve(C->varlist_size());
8173 for (auto *VE : C->varlists()) {
8174 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8175 if (EVar.isInvalid())
8176 return nullptr;
8177 Vars.push_back(EVar.get());
8178 }
8179 return getDerived().RebuildOMPIsDevicePtrClause(
8180 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8181}
8182
Douglas Gregorebe10102009-08-20 07:17:43 +00008183//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008184// Expression transformation
8185//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008188TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008189 if (!E->isTypeDependent())
8190 return E;
8191
8192 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8193 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008194}
Mike Stump11289f42009-09-09 15:08:12 +00008195
8196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008198TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008199 NestedNameSpecifierLoc QualifierLoc;
8200 if (E->getQualifierLoc()) {
8201 QualifierLoc
8202 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8203 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008204 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008205 }
John McCallce546572009-12-08 09:08:17 +00008206
8207 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008208 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8209 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008210 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008211 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008212
John McCall815039a2010-08-17 21:27:17 +00008213 DeclarationNameInfo NameInfo = E->getNameInfo();
8214 if (NameInfo.getName()) {
8215 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8216 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008218 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008219
8220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008221 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008222 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008223 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008224 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008225
8226 // Mark it referenced in the new context regardless.
8227 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008228 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008229
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008230 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008231 }
John McCallce546572009-12-08 09:08:17 +00008232
Craig Topperc3ec1492014-05-26 06:22:03 +00008233 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008234 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008235 TemplateArgs = &TransArgs;
8236 TransArgs.setLAngleLoc(E->getLAngleLoc());
8237 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008238 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8239 E->getNumTemplateArgs(),
8240 TransArgs))
8241 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008242 }
8243
Chad Rosier1dcde962012-08-08 18:46:20 +00008244 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008245 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008246}
Mike Stump11289f42009-09-09 15:08:12 +00008247
Douglas Gregora16548e2009-08-11 05:31:07 +00008248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008250TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008251 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008252}
Mike Stump11289f42009-09-09 15:08:12 +00008253
Douglas Gregora16548e2009-08-11 05:31:07 +00008254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008256TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008257 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008258}
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregora16548e2009-08-11 05:31:07 +00008260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008262TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008263 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008264}
Mike Stump11289f42009-09-09 15:08:12 +00008265
Douglas Gregora16548e2009-08-11 05:31:07 +00008266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008268TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008269 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008270}
Mike Stump11289f42009-09-09 15:08:12 +00008271
Douglas Gregora16548e2009-08-11 05:31:07 +00008272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008274TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008275 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008276}
8277
8278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008279ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008280TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008281 if (FunctionDecl *FD = E->getDirectCallee())
8282 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008283 return SemaRef.MaybeBindToTemporary(E);
8284}
8285
8286template<typename Derived>
8287ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008288TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8289 ExprResult ControllingExpr =
8290 getDerived().TransformExpr(E->getControllingExpr());
8291 if (ControllingExpr.isInvalid())
8292 return ExprError();
8293
Chris Lattner01cf8db2011-07-20 06:58:45 +00008294 SmallVector<Expr *, 4> AssocExprs;
8295 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008296 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8297 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8298 if (TS) {
8299 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8300 if (!AssocType)
8301 return ExprError();
8302 AssocTypes.push_back(AssocType);
8303 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008304 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008305 }
8306
8307 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8308 if (AssocExpr.isInvalid())
8309 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008310 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008311 }
8312
8313 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8314 E->getDefaultLoc(),
8315 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008316 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008317 AssocTypes,
8318 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008319}
8320
8321template<typename Derived>
8322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008323TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008324 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008325 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008327
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008329 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008330
John McCallb268a282010-08-23 23:25:46 +00008331 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008332 E->getRParen());
8333}
8334
Richard Smithdb2630f2012-10-21 03:28:35 +00008335/// \brief The operand of a unary address-of operator has special rules: it's
8336/// allowed to refer to a non-static member of a class even if there's no 'this'
8337/// object available.
8338template<typename Derived>
8339ExprResult
8340TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8341 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008342 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008343 else
8344 return getDerived().TransformExpr(E);
8345}
8346
Mike Stump11289f42009-09-09 15:08:12 +00008347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008349TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008350 ExprResult SubExpr;
8351 if (E->getOpcode() == UO_AddrOf)
8352 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8353 else
8354 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008355 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008357
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008359 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8362 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008363 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008364}
Mike Stump11289f42009-09-09 15:08:12 +00008365
Douglas Gregora16548e2009-08-11 05:31:07 +00008366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008367ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008368TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8369 // Transform the type.
8370 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8371 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008372 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008373
Douglas Gregor882211c2010-04-28 22:16:22 +00008374 // Transform all of the components into components similar to what the
8375 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008376 // FIXME: It would be slightly more efficient in the non-dependent case to
8377 // just map FieldDecls, rather than requiring the rebuilder to look for
8378 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008379 // template code that we don't care.
8380 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008381 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008382 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008383 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008384 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008385 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008386 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008387 Comp.LocStart = ON.getSourceRange().getBegin();
8388 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008389 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008390 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008391 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008392 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008393 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008394 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008395
Douglas Gregor882211c2010-04-28 22:16:22 +00008396 ExprChanged = ExprChanged || Index.get() != FromIndex;
8397 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008398 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008399 break;
8400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008401
James Y Knight7281c352015-12-29 22:31:18 +00008402 case OffsetOfNode::Field:
8403 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008404 Comp.isBrackets = false;
8405 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008406 if (!Comp.U.IdentInfo)
8407 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008408
Douglas Gregor882211c2010-04-28 22:16:22 +00008409 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008410
James Y Knight7281c352015-12-29 22:31:18 +00008411 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008412 // Will be recomputed during the rebuild.
8413 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008415
Douglas Gregor882211c2010-04-28 22:16:22 +00008416 Components.push_back(Comp);
8417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008418
Douglas Gregor882211c2010-04-28 22:16:22 +00008419 // If nothing changed, retain the existing expression.
8420 if (!getDerived().AlwaysRebuild() &&
8421 Type == E->getTypeSourceInfo() &&
8422 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008423 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008424
Douglas Gregor882211c2010-04-28 22:16:22 +00008425 // Build a new offsetof expression.
8426 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008427 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008428}
8429
8430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008431ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008432TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008433 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008434 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008435 return E;
John McCall8d69a212010-11-15 23:31:06 +00008436}
8437
8438template<typename Derived>
8439ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008440TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8441 return E;
8442}
8443
8444template<typename Derived>
8445ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008446TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008447 // Rebuild the syntactic form. The original syntactic form has
8448 // opaque-value expressions in it, so strip those away and rebuild
8449 // the result. This is a really awful way of doing this, but the
8450 // better solution (rebuilding the semantic expressions and
8451 // rebinding OVEs as necessary) doesn't work; we'd need
8452 // TreeTransform to not strip away implicit conversions.
8453 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8454 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008455 if (result.isInvalid()) return ExprError();
8456
8457 // If that gives us a pseudo-object result back, the pseudo-object
8458 // expression must have been an lvalue-to-rvalue conversion which we
8459 // should reapply.
8460 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008461 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008462
8463 return result;
8464}
8465
8466template<typename Derived>
8467ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008468TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8469 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008470 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008471 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008472
John McCallbcd03502009-12-07 02:54:59 +00008473 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008474 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008476
John McCall4c98fd82009-11-04 07:28:41 +00008477 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008478 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008479
Peter Collingbournee190dee2011-03-11 19:24:49 +00008480 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8481 E->getKind(),
8482 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008483 }
Mike Stump11289f42009-09-09 15:08:12 +00008484
Eli Friedmane4f22df2012-02-29 04:03:55 +00008485 // C++0x [expr.sizeof]p1:
8486 // The operand is either an expression, which is an unevaluated operand
8487 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008488 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8489 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008490
Reid Kleckner32506ed2014-06-12 23:03:48 +00008491 // Try to recover if we have something like sizeof(T::X) where X is a type.
8492 // Notably, there must be *exactly* one set of parens if X is a type.
8493 TypeSourceInfo *RecoveryTSI = nullptr;
8494 ExprResult SubExpr;
8495 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8496 if (auto *DRE =
8497 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8498 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8499 PE, DRE, false, &RecoveryTSI);
8500 else
8501 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8502
8503 if (RecoveryTSI) {
8504 return getDerived().RebuildUnaryExprOrTypeTrait(
8505 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8506 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008508
Eli Friedmane4f22df2012-02-29 04:03:55 +00008509 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008510 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008511
Peter Collingbournee190dee2011-03-11 19:24:49 +00008512 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8513 E->getOperatorLoc(),
8514 E->getKind(),
8515 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008516}
Mike Stump11289f42009-09-09 15:08:12 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008520TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008521 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008522 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008524
John McCalldadc5752010-08-24 06:29:42 +00008525 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008528
8529
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 if (!getDerived().AlwaysRebuild() &&
8531 LHS.get() == E->getLHS() &&
8532 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008533 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008534
John McCallb268a282010-08-23 23:25:46 +00008535 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008537 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 E->getRBracketLoc());
8539}
Mike Stump11289f42009-09-09 15:08:12 +00008540
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008541template <typename Derived>
8542ExprResult
8543TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8544 ExprResult Base = getDerived().TransformExpr(E->getBase());
8545 if (Base.isInvalid())
8546 return ExprError();
8547
8548 ExprResult LowerBound;
8549 if (E->getLowerBound()) {
8550 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8551 if (LowerBound.isInvalid())
8552 return ExprError();
8553 }
8554
8555 ExprResult Length;
8556 if (E->getLength()) {
8557 Length = getDerived().TransformExpr(E->getLength());
8558 if (Length.isInvalid())
8559 return ExprError();
8560 }
8561
8562 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8563 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8564 return E;
8565
8566 return getDerived().RebuildOMPArraySectionExpr(
8567 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8568 Length.get(), E->getRBracketLoc());
8569}
8570
Mike Stump11289f42009-09-09 15:08:12 +00008571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008573TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008575 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008577 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008578
8579 // Transform arguments.
8580 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008581 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008582 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008583 &ArgChanged))
8584 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008585
Douglas Gregora16548e2009-08-11 05:31:07 +00008586 if (!getDerived().AlwaysRebuild() &&
8587 Callee.get() == E->getCallee() &&
8588 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008589 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008590
Douglas Gregora16548e2009-08-11 05:31:07 +00008591 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008592 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008593 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008594 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008595 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008596 E->getRParenLoc());
8597}
Mike Stump11289f42009-09-09 15:08:12 +00008598
8599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008600ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008601TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008602 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008605
Douglas Gregorea972d32011-02-28 21:54:11 +00008606 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008607 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008608 QualifierLoc
8609 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008610
Douglas Gregorea972d32011-02-28 21:54:11 +00008611 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008612 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008613 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008614 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008615
Eli Friedman2cfcef62009-12-04 06:40:45 +00008616 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008617 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8618 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008619 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008621
John McCall16df1e52010-03-30 21:47:33 +00008622 NamedDecl *FoundDecl = E->getFoundDecl();
8623 if (FoundDecl == E->getMemberDecl()) {
8624 FoundDecl = Member;
8625 } else {
8626 FoundDecl = cast_or_null<NamedDecl>(
8627 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8628 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008629 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008630 }
8631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 if (!getDerived().AlwaysRebuild() &&
8633 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008634 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008635 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008636 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008637 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008638
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008639 // Mark it referenced in the new context regardless.
8640 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008641 SemaRef.MarkMemberReferenced(E);
8642
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008643 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008644 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008645
John McCall6b51f282009-11-23 01:53:49 +00008646 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008647 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008648 TransArgs.setLAngleLoc(E->getLAngleLoc());
8649 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008650 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8651 E->getNumTemplateArgs(),
8652 TransArgs))
8653 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008654 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008655
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008657 SourceLocation FakeOperatorLoc =
8658 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008659
John McCall38836f02010-01-15 08:34:02 +00008660 // FIXME: to do this check properly, we will need to preserve the
8661 // first-qualifier-in-scope here, just in case we had a dependent
8662 // base (and therefore couldn't do the check) and a
8663 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008664 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008665
John McCallb268a282010-08-23 23:25:46 +00008666 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008667 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008668 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008669 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008670 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008671 Member,
John McCall16df1e52010-03-30 21:47:33 +00008672 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008673 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008674 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008675 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008676}
Mike Stump11289f42009-09-09 15:08:12 +00008677
Douglas Gregora16548e2009-08-11 05:31:07 +00008678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008680TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008681 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008684
John McCalldadc5752010-08-24 06:29:42 +00008685 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008688
Douglas Gregora16548e2009-08-11 05:31:07 +00008689 if (!getDerived().AlwaysRebuild() &&
8690 LHS.get() == E->getLHS() &&
8691 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008692 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008693
Lang Hames5de91cc2012-10-02 04:45:10 +00008694 Sema::FPContractStateRAII FPContractState(getSema());
8695 getSema().FPFeatures.fp_contract = E->isFPContractable();
8696
Douglas Gregora16548e2009-08-11 05:31:07 +00008697 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008698 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008699}
8700
Mike Stump11289f42009-09-09 15:08:12 +00008701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008702ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008703TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008704 CompoundAssignOperator *E) {
8705 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008706}
Mike Stump11289f42009-09-09 15:08:12 +00008707
Douglas Gregora16548e2009-08-11 05:31:07 +00008708template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008709ExprResult TreeTransform<Derived>::
8710TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8711 // Just rebuild the common and RHS expressions and see whether we
8712 // get any changes.
8713
8714 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8715 if (commonExpr.isInvalid())
8716 return ExprError();
8717
8718 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8719 if (rhs.isInvalid())
8720 return ExprError();
8721
8722 if (!getDerived().AlwaysRebuild() &&
8723 commonExpr.get() == e->getCommon() &&
8724 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008725 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008726
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008727 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008728 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008729 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008730 e->getColonLoc(),
8731 rhs.get());
8732}
8733
8734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008736TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008737 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008738 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008740
John McCalldadc5752010-08-24 06:29:42 +00008741 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008744
John McCalldadc5752010-08-24 06:29:42 +00008745 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008748
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 if (!getDerived().AlwaysRebuild() &&
8750 Cond.get() == E->getCond() &&
8751 LHS.get() == E->getLHS() &&
8752 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008753 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008754
John McCallb268a282010-08-23 23:25:46 +00008755 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008756 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008757 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008758 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008759 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008760}
Mike Stump11289f42009-09-09 15:08:12 +00008761
8762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008764TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008765 // Implicit casts are eliminated during transformation, since they
8766 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008767 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008768}
Mike Stump11289f42009-09-09 15:08:12 +00008769
Douglas Gregora16548e2009-08-11 05:31:07 +00008770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008772TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008773 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8774 if (!Type)
8775 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008776
John McCalldadc5752010-08-24 06:29:42 +00008777 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008778 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008779 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008781
Douglas Gregora16548e2009-08-11 05:31:07 +00008782 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008783 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008784 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008785 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008786
John McCall97513962010-01-15 18:39:57 +00008787 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008788 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008789 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008790 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008791}
Mike Stump11289f42009-09-09 15:08:12 +00008792
Douglas Gregora16548e2009-08-11 05:31:07 +00008793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008795TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008796 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8797 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8798 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008800
John McCalldadc5752010-08-24 06:29:42 +00008801 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008802 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008804
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008806 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008808 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008809
John McCall5d7aa7f2010-01-19 22:33:45 +00008810 // Note: the expression type doesn't necessarily match the
8811 // type-as-written, but that's okay, because it should always be
8812 // derivable from the initializer.
8813
John McCalle15bbff2010-01-18 19:35:47 +00008814 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008816 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008817}
Mike Stump11289f42009-09-09 15:08:12 +00008818
Douglas Gregora16548e2009-08-11 05:31:07 +00008819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008821TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008822 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008823 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 if (!getDerived().AlwaysRebuild() &&
8827 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008828 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008829
Douglas Gregora16548e2009-08-11 05:31:07 +00008830 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008831 SourceLocation FakeOperatorLoc =
8832 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008833 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008834 E->getAccessorLoc(),
8835 E->getAccessor());
8836}
Mike Stump11289f42009-09-09 15:08:12 +00008837
Douglas Gregora16548e2009-08-11 05:31:07 +00008838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008840TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008841 if (InitListExpr *Syntactic = E->getSyntacticForm())
8842 E = Syntactic;
8843
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008845
Benjamin Kramerf0623432012-08-23 22:51:59 +00008846 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008847 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008848 Inits, &InitChanged))
8849 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008850
Richard Smith520449d2015-02-05 06:15:50 +00008851 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8852 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8853 // in some cases. We can't reuse it in general, because the syntactic and
8854 // semantic forms are linked, and we can't know that semantic form will
8855 // match even if the syntactic form does.
8856 }
Mike Stump11289f42009-09-09 15:08:12 +00008857
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008858 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008859 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008860}
Mike Stump11289f42009-09-09 15:08:12 +00008861
Douglas Gregora16548e2009-08-11 05:31:07 +00008862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008864TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008866
Douglas Gregorebe10102009-08-20 07:17:43 +00008867 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008868 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008871
Douglas Gregorebe10102009-08-20 07:17:43 +00008872 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008873 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008874 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008875 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8876 if (D.isFieldDesignator()) {
8877 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8878 D.getDotLoc(),
8879 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 continue;
8881 }
Mike Stump11289f42009-09-09 15:08:12 +00008882
David Majnemerf7e36092016-06-23 00:15:04 +00008883 if (D.isArrayDesignator()) {
8884 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008887
David Majnemerf7e36092016-06-23 00:15:04 +00008888 Desig.AddDesignator(
8889 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008890
David Majnemerf7e36092016-06-23 00:15:04 +00008891 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008892 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 continue;
8894 }
Mike Stump11289f42009-09-09 15:08:12 +00008895
David Majnemerf7e36092016-06-23 00:15:04 +00008896 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008897 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008898 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008899 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008901
David Majnemerf7e36092016-06-23 00:15:04 +00008902 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008903 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008905
8906 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008908 D.getLBracketLoc(),
8909 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008910
David Majnemerf7e36092016-06-23 00:15:04 +00008911 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8912 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008913
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008914 ArrayExprs.push_back(Start.get());
8915 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008916 }
Mike Stump11289f42009-09-09 15:08:12 +00008917
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 if (!getDerived().AlwaysRebuild() &&
8919 Init.get() == E->getInit() &&
8920 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008921 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008922
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008923 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008924 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008925 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008926}
Mike Stump11289f42009-09-09 15:08:12 +00008927
Yunzhong Gaocb779302015-06-10 00:27:52 +00008928// Seems that if TransformInitListExpr() only works on the syntactic form of an
8929// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8930template<typename Derived>
8931ExprResult
8932TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8933 DesignatedInitUpdateExpr *E) {
8934 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8935 "initializer");
8936 return ExprError();
8937}
8938
8939template<typename Derived>
8940ExprResult
8941TreeTransform<Derived>::TransformNoInitExpr(
8942 NoInitExpr *E) {
8943 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8944 return ExprError();
8945}
8946
Douglas Gregora16548e2009-08-11 05:31:07 +00008947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008948ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008949TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008950 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008951 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008952
Douglas Gregor3da3c062009-10-28 00:29:27 +00008953 // FIXME: Will we ever have proper type location here? Will we actually
8954 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 QualType T = getDerived().TransformType(E->getType());
8956 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008958
Douglas Gregora16548e2009-08-11 05:31:07 +00008959 if (!getDerived().AlwaysRebuild() &&
8960 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008961 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008962
Douglas Gregora16548e2009-08-11 05:31:07 +00008963 return getDerived().RebuildImplicitValueInitExpr(T);
8964}
Mike Stump11289f42009-09-09 15:08:12 +00008965
Douglas Gregora16548e2009-08-11 05:31:07 +00008966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008968TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008969 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8970 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008972
John McCalldadc5752010-08-24 06:29:42 +00008973 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008974 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008976
Douglas Gregora16548e2009-08-11 05:31:07 +00008977 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008978 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008979 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008980 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008981
John McCallb268a282010-08-23 23:25:46 +00008982 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008983 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008984}
8985
8986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008988TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008989 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008990 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008991 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8992 &ArgumentChanged))
8993 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008994
Douglas Gregora16548e2009-08-11 05:31:07 +00008995 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008996 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008997 E->getRParenLoc());
8998}
Mike Stump11289f42009-09-09 15:08:12 +00008999
Douglas Gregora16548e2009-08-11 05:31:07 +00009000/// \brief Transform an address-of-label expression.
9001///
9002/// By default, the transformation of an address-of-label expression always
9003/// rebuilds the expression, so that the label identifier can be resolved to
9004/// the corresponding label statement by semantic analysis.
9005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009007TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009008 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9009 E->getLabel());
9010 if (!LD)
9011 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009012
Douglas Gregora16548e2009-08-11 05:31:07 +00009013 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009014 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009015}
Mike Stump11289f42009-09-09 15:08:12 +00009016
9017template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009018ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009019TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009020 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009021 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009023 if (SubStmt.isInvalid()) {
9024 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009025 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009026 }
Mike Stump11289f42009-09-09 15:08:12 +00009027
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009029 SubStmt.get() == E->getSubStmt()) {
9030 // Calling this an 'error' is unintuitive, but it does the right thing.
9031 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009032 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009033 }
Mike Stump11289f42009-09-09 15:08:12 +00009034
9035 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009036 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009037 E->getRParenLoc());
9038}
Mike Stump11289f42009-09-09 15:08:12 +00009039
Douglas Gregora16548e2009-08-11 05:31:07 +00009040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009042TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009043 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009044 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009046
John McCalldadc5752010-08-24 06:29:42 +00009047 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009048 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009050
John McCalldadc5752010-08-24 06:29:42 +00009051 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009052 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 if (!getDerived().AlwaysRebuild() &&
9056 Cond.get() == E->getCond() &&
9057 LHS.get() == E->getLHS() &&
9058 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009059 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009060
Douglas Gregora16548e2009-08-11 05:31:07 +00009061 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009062 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009063 E->getRParenLoc());
9064}
Mike Stump11289f42009-09-09 15:08:12 +00009065
Douglas Gregora16548e2009-08-11 05:31:07 +00009066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009068TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009069 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009070}
9071
9072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009074TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009075 switch (E->getOperator()) {
9076 case OO_New:
9077 case OO_Delete:
9078 case OO_Array_New:
9079 case OO_Array_Delete:
9080 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009081
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009082 case OO_Call: {
9083 // This is a call to an object's operator().
9084 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9085
9086 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009087 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009088 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009089 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009090
9091 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009092 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9093 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009094
9095 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009096 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009097 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009098 Args))
9099 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009100
John McCallb268a282010-08-23 23:25:46 +00009101 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009102 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009103 E->getLocEnd());
9104 }
9105
9106#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9107 case OO_##Name:
9108#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9109#include "clang/Basic/OperatorKinds.def"
9110 case OO_Subscript:
9111 // Handled below.
9112 break;
9113
9114 case OO_Conditional:
9115 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009116
9117 case OO_None:
9118 case NUM_OVERLOADED_OPERATORS:
9119 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009120 }
9121
John McCalldadc5752010-08-24 06:29:42 +00009122 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009123 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009125
Richard Smithdb2630f2012-10-21 03:28:35 +00009126 ExprResult First;
9127 if (E->getOperator() == OO_Amp)
9128 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9129 else
9130 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009132 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009133
John McCalldadc5752010-08-24 06:29:42 +00009134 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009135 if (E->getNumArgs() == 2) {
9136 Second = getDerived().TransformExpr(E->getArg(1));
9137 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009138 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009139 }
Mike Stump11289f42009-09-09 15:08:12 +00009140
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 if (!getDerived().AlwaysRebuild() &&
9142 Callee.get() == E->getCallee() &&
9143 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009144 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009145 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009146
Lang Hames5de91cc2012-10-02 04:45:10 +00009147 Sema::FPContractStateRAII FPContractState(getSema());
9148 getSema().FPFeatures.fp_contract = E->isFPContractable();
9149
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9151 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009152 Callee.get(),
9153 First.get(),
9154 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009155}
Mike Stump11289f42009-09-09 15:08:12 +00009156
Douglas Gregora16548e2009-08-11 05:31:07 +00009157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009159TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9160 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009161}
Mike Stump11289f42009-09-09 15:08:12 +00009162
Douglas Gregora16548e2009-08-11 05:31:07 +00009163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009164ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009165TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9166 // Transform the callee.
9167 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9168 if (Callee.isInvalid())
9169 return ExprError();
9170
9171 // Transform exec config.
9172 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9173 if (EC.isInvalid())
9174 return ExprError();
9175
9176 // Transform arguments.
9177 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009178 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009179 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009180 &ArgChanged))
9181 return ExprError();
9182
9183 if (!getDerived().AlwaysRebuild() &&
9184 Callee.get() == E->getCallee() &&
9185 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009186 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009187
9188 // FIXME: Wrong source location information for the '('.
9189 SourceLocation FakeLParenLoc
9190 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9191 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009192 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009193 E->getRParenLoc(), EC.get());
9194}
9195
9196template<typename Derived>
9197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009198TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009199 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9200 if (!Type)
9201 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009202
John McCalldadc5752010-08-24 06:29:42 +00009203 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009204 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009205 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregora16548e2009-08-11 05:31:07 +00009208 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009209 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009210 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009211 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009212 return getDerived().RebuildCXXNamedCastExpr(
9213 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9214 Type, E->getAngleBrackets().getEnd(),
9215 // FIXME. this should be '(' location
9216 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009217}
Mike Stump11289f42009-09-09 15:08:12 +00009218
Douglas Gregora16548e2009-08-11 05:31:07 +00009219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009221TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9222 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009223}
Mike Stump11289f42009-09-09 15:08:12 +00009224
9225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009227TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9228 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009229}
9230
Douglas Gregora16548e2009-08-11 05:31:07 +00009231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009232ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009233TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009234 CXXReinterpretCastExpr *E) {
9235 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009236}
Mike Stump11289f42009-09-09 15:08:12 +00009237
Douglas Gregora16548e2009-08-11 05:31:07 +00009238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009240TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9241 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009242}
Mike Stump11289f42009-09-09 15:08:12 +00009243
Douglas Gregora16548e2009-08-11 05:31:07 +00009244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009245ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009246TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009247 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009248 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9249 if (!Type)
9250 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009251
John McCalldadc5752010-08-24 06:29:42 +00009252 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009253 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009256
Douglas Gregora16548e2009-08-11 05:31:07 +00009257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009258 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009259 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009260 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009261
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009262 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009263 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009264 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009265 E->getRParenLoc());
9266}
Mike Stump11289f42009-09-09 15:08:12 +00009267
Douglas Gregora16548e2009-08-11 05:31:07 +00009268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009270TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009272 TypeSourceInfo *TInfo
9273 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9274 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009276
Douglas Gregora16548e2009-08-11 05:31:07 +00009277 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009278 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009279 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009280
Douglas Gregor9da64192010-04-26 22:37:10 +00009281 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9282 E->getLocStart(),
9283 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 E->getLocEnd());
9285 }
Mike Stump11289f42009-09-09 15:08:12 +00009286
Eli Friedman456f0182012-01-20 01:26:23 +00009287 // We don't know whether the subexpression is potentially evaluated until
9288 // after we perform semantic analysis. We speculatively assume it is
9289 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009290 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009291 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9292 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009293
John McCalldadc5752010-08-24 06:29:42 +00009294 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009295 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009297
Douglas Gregora16548e2009-08-11 05:31:07 +00009298 if (!getDerived().AlwaysRebuild() &&
9299 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009300 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009301
Douglas Gregor9da64192010-04-26 22:37:10 +00009302 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9303 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009304 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009305 E->getLocEnd());
9306}
9307
9308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009309ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009310TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9311 if (E->isTypeOperand()) {
9312 TypeSourceInfo *TInfo
9313 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9314 if (!TInfo)
9315 return ExprError();
9316
9317 if (!getDerived().AlwaysRebuild() &&
9318 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009319 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009320
Douglas Gregor69735112011-03-06 17:40:41 +00009321 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009322 E->getLocStart(),
9323 TInfo,
9324 E->getLocEnd());
9325 }
9326
Francois Pichet9f4f2072010-09-08 12:20:18 +00009327 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9328
9329 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9330 if (SubExpr.isInvalid())
9331 return ExprError();
9332
9333 if (!getDerived().AlwaysRebuild() &&
9334 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009335 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009336
9337 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9338 E->getLocStart(),
9339 SubExpr.get(),
9340 E->getLocEnd());
9341}
9342
9343template<typename Derived>
9344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009345TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009346 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009347}
Mike Stump11289f42009-09-09 15:08:12 +00009348
Douglas Gregora16548e2009-08-11 05:31:07 +00009349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009350ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009351TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009352 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009353 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009354}
Mike Stump11289f42009-09-09 15:08:12 +00009355
Douglas Gregora16548e2009-08-11 05:31:07 +00009356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009358TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009359 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009360
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009361 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9362 // Make sure that we capture 'this'.
9363 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009364 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009366
Douglas Gregorb15af892010-01-07 23:12:05 +00009367 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009368}
Mike Stump11289f42009-09-09 15:08:12 +00009369
Douglas Gregora16548e2009-08-11 05:31:07 +00009370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009372TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009373 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009374 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009376
Douglas Gregora16548e2009-08-11 05:31:07 +00009377 if (!getDerived().AlwaysRebuild() &&
9378 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009379 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009380
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009381 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9382 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009383}
Mike Stump11289f42009-09-09 15:08:12 +00009384
Douglas Gregora16548e2009-08-11 05:31:07 +00009385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009387TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009388 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009389 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9390 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009391 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009393
Chandler Carruth794da4c2010-02-08 06:42:49 +00009394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009396 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009397
Douglas Gregor033f6752009-12-23 23:03:06 +00009398 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009399}
Mike Stump11289f42009-09-09 15:08:12 +00009400
Douglas Gregora16548e2009-08-11 05:31:07 +00009401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009402ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009403TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9404 FieldDecl *Field
9405 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9406 E->getField()));
9407 if (!Field)
9408 return ExprError();
9409
9410 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009411 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009412
9413 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9414}
9415
9416template<typename Derived>
9417ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009418TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9419 CXXScalarValueInitExpr *E) {
9420 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9421 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009422 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009423
Douglas Gregora16548e2009-08-11 05:31:07 +00009424 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009425 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009426 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009427
Chad Rosier1dcde962012-08-08 18:46:20 +00009428 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009429 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009430 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009431}
Mike Stump11289f42009-09-09 15:08:12 +00009432
Douglas Gregora16548e2009-08-11 05:31:07 +00009433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009435TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009436 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009437 TypeSourceInfo *AllocTypeInfo
9438 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9439 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009441
Douglas Gregora16548e2009-08-11 05:31:07 +00009442 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009443 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009444 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009446
Douglas Gregora16548e2009-08-11 05:31:07 +00009447 // Transform the placement arguments (if any).
9448 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009449 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009450 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009451 E->getNumPlacementArgs(), true,
9452 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009454
Sebastian Redl6047f072012-02-16 12:22:20 +00009455 // Transform the initializer (if any).
9456 Expr *OldInit = E->getInitializer();
9457 ExprResult NewInit;
9458 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009459 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009460 if (NewInit.isInvalid())
9461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009462
Sebastian Redl6047f072012-02-16 12:22:20 +00009463 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009464 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009465 if (E->getOperatorNew()) {
9466 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009467 getDerived().TransformDecl(E->getLocStart(),
9468 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009469 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009470 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009471 }
9472
Craig Topperc3ec1492014-05-26 06:22:03 +00009473 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009474 if (E->getOperatorDelete()) {
9475 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009476 getDerived().TransformDecl(E->getLocStart(),
9477 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009478 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009479 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009481
Douglas Gregora16548e2009-08-11 05:31:07 +00009482 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009483 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009485 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009486 OperatorNew == E->getOperatorNew() &&
9487 OperatorDelete == E->getOperatorDelete() &&
9488 !ArgumentChanged) {
9489 // Mark any declarations we need as referenced.
9490 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009491 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009492 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009493 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009494 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009495
Sebastian Redl6047f072012-02-16 12:22:20 +00009496 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009497 QualType ElementType
9498 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9499 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9500 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9501 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009502 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009503 }
9504 }
9505 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009506
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009507 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009508 }
Mike Stump11289f42009-09-09 15:08:12 +00009509
Douglas Gregor0744ef62010-09-07 21:49:58 +00009510 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009511 if (!ArraySize.get()) {
9512 // If no array size was specified, but the new expression was
9513 // instantiated with an array type (e.g., "new T" where T is
9514 // instantiated with "int[4]"), extract the outer bound from the
9515 // array type as our array size. We do this with constant and
9516 // dependently-sized array types.
9517 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9518 if (!ArrayT) {
9519 // Do nothing
9520 } else if (const ConstantArrayType *ConsArrayT
9521 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009522 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9523 SemaRef.Context.getSizeType(),
9524 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009525 AllocType = ConsArrayT->getElementType();
9526 } else if (const DependentSizedArrayType *DepArrayT
9527 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9528 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009529 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009530 AllocType = DepArrayT->getElementType();
9531 }
9532 }
9533 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009534
Douglas Gregora16548e2009-08-11 05:31:07 +00009535 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9536 E->isGlobalNew(),
9537 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009538 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009539 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009540 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009541 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009542 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009543 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009544 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009545 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009546}
Mike Stump11289f42009-09-09 15:08:12 +00009547
Douglas Gregora16548e2009-08-11 05:31:07 +00009548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009550TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009551 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009552 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009554
Douglas Gregord2d9da02010-02-26 00:38:10 +00009555 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009556 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009557 if (E->getOperatorDelete()) {
9558 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009559 getDerived().TransformDecl(E->getLocStart(),
9560 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009561 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009562 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009564
Douglas Gregora16548e2009-08-11 05:31:07 +00009565 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009566 Operand.get() == E->getArgument() &&
9567 OperatorDelete == E->getOperatorDelete()) {
9568 // Mark any declarations we need as referenced.
9569 // FIXME: instantiation-specific.
9570 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009571 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009572
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009573 if (!E->getArgument()->isTypeDependent()) {
9574 QualType Destroyed = SemaRef.Context.getBaseElementType(
9575 E->getDestroyedType());
9576 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9577 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009578 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009579 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009580 }
9581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009582
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009583 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009584 }
Mike Stump11289f42009-09-09 15:08:12 +00009585
Douglas Gregora16548e2009-08-11 05:31:07 +00009586 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9587 E->isGlobalDelete(),
9588 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009589 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009590}
Mike Stump11289f42009-09-09 15:08:12 +00009591
Douglas Gregora16548e2009-08-11 05:31:07 +00009592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009593ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009594TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009595 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009596 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009597 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009599
John McCallba7bf592010-08-24 05:47:05 +00009600 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009601 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009602 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009603 E->getOperatorLoc(),
9604 E->isArrow()? tok::arrow : tok::period,
9605 ObjectTypePtr,
9606 MayBePseudoDestructor);
9607 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009608 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009609
John McCallba7bf592010-08-24 05:47:05 +00009610 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009611 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9612 if (QualifierLoc) {
9613 QualifierLoc
9614 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9615 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009616 return ExprError();
9617 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009618 CXXScopeSpec SS;
9619 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009620
Douglas Gregor678f90d2010-02-25 01:56:36 +00009621 PseudoDestructorTypeStorage Destroyed;
9622 if (E->getDestroyedTypeInfo()) {
9623 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009624 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009625 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009626 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009627 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009628 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009629 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009630 // We aren't likely to be able to resolve the identifier down to a type
9631 // now anyway, so just retain the identifier.
9632 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9633 E->getDestroyedTypeLoc());
9634 } else {
9635 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009636 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009637 *E->getDestroyedTypeIdentifier(),
9638 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009639 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009640 SS, ObjectTypePtr,
9641 false);
9642 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009643 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009644
Douglas Gregor678f90d2010-02-25 01:56:36 +00009645 Destroyed
9646 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9647 E->getDestroyedTypeLoc());
9648 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009649
Craig Topperc3ec1492014-05-26 06:22:03 +00009650 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009651 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009652 CXXScopeSpec EmptySS;
9653 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009654 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009655 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009656 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009658
John McCallb268a282010-08-23 23:25:46 +00009659 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009660 E->getOperatorLoc(),
9661 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009662 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009663 ScopeTypeInfo,
9664 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009665 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009666 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009667}
Mike Stump11289f42009-09-09 15:08:12 +00009668
Douglas Gregorad8a3362009-09-04 17:36:40 +00009669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009670ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009671TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009672 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009673 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9674 Sema::LookupOrdinaryName);
9675
9676 // Transform all the decls.
9677 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9678 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009679 NamedDecl *InstD = static_cast<NamedDecl*>(
9680 getDerived().TransformDecl(Old->getNameLoc(),
9681 *I));
John McCall84d87672009-12-10 09:41:52 +00009682 if (!InstD) {
9683 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9684 // This can happen because of dependent hiding.
9685 if (isa<UsingShadowDecl>(*I))
9686 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009687 else {
9688 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009689 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009690 }
John McCall84d87672009-12-10 09:41:52 +00009691 }
John McCalle66edc12009-11-24 19:00:30 +00009692
9693 // Expand using declarations.
9694 if (isa<UsingDecl>(InstD)) {
9695 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009696 for (auto *I : UD->shadows())
9697 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009698 continue;
9699 }
9700
9701 R.addDecl(InstD);
9702 }
9703
9704 // Resolve a kind, but don't do any further analysis. If it's
9705 // ambiguous, the callee needs to deal with it.
9706 R.resolveKind();
9707
9708 // Rebuild the nested-name qualifier, if present.
9709 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009710 if (Old->getQualifierLoc()) {
9711 NestedNameSpecifierLoc QualifierLoc
9712 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9713 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009714 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009715
Douglas Gregor0da1d432011-02-28 20:01:57 +00009716 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009717 }
9718
Douglas Gregor9262f472010-04-27 18:19:34 +00009719 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009720 CXXRecordDecl *NamingClass
9721 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9722 Old->getNameLoc(),
9723 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009724 if (!NamingClass) {
9725 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009726 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009728
Douglas Gregorda7be082010-04-27 16:10:10 +00009729 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009730 }
9731
Abramo Bagnara7945c982012-01-27 09:46:47 +00009732 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9733
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009734 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009735 // it's a normal declaration name or member reference.
9736 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9737 NamedDecl *D = R.getAsSingle<NamedDecl>();
9738 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9739 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9740 // give a good diagnostic.
9741 if (D && D->isCXXInstanceMember()) {
9742 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9743 /*TemplateArgs=*/nullptr,
9744 /*Scope=*/nullptr);
9745 }
9746
John McCalle66edc12009-11-24 19:00:30 +00009747 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009748 }
John McCalle66edc12009-11-24 19:00:30 +00009749
9750 // If we have template arguments, rebuild them, then rebuild the
9751 // templateid expression.
9752 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009753 if (Old->hasExplicitTemplateArgs() &&
9754 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009755 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009756 TransArgs)) {
9757 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009758 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009759 }
John McCalle66edc12009-11-24 19:00:30 +00009760
Abramo Bagnara7945c982012-01-27 09:46:47 +00009761 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009762 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009763}
Mike Stump11289f42009-09-09 15:08:12 +00009764
Douglas Gregora16548e2009-08-11 05:31:07 +00009765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009766ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009767TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9768 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009769 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009770 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9771 TypeSourceInfo *From = E->getArg(I);
9772 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009773 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009774 TypeLocBuilder TLB;
9775 TLB.reserve(FromTL.getFullDataSize());
9776 QualType To = getDerived().TransformType(TLB, FromTL);
9777 if (To.isNull())
9778 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009779
Douglas Gregor29c42f22012-02-24 07:38:34 +00009780 if (To == From->getType())
9781 Args.push_back(From);
9782 else {
9783 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9784 ArgChanged = true;
9785 }
9786 continue;
9787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009788
Douglas Gregor29c42f22012-02-24 07:38:34 +00009789 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009790
Douglas Gregor29c42f22012-02-24 07:38:34 +00009791 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009792 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009793 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9794 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9795 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009796
Douglas Gregor29c42f22012-02-24 07:38:34 +00009797 // Determine whether the set of unexpanded parameter packs can and should
9798 // be expanded.
9799 bool Expand = true;
9800 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009801 Optional<unsigned> OrigNumExpansions =
9802 ExpansionTL.getTypePtr()->getNumExpansions();
9803 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009804 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9805 PatternTL.getSourceRange(),
9806 Unexpanded,
9807 Expand, RetainExpansion,
9808 NumExpansions))
9809 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009810
Douglas Gregor29c42f22012-02-24 07:38:34 +00009811 if (!Expand) {
9812 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009813 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009814 // expansion.
9815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009816
Douglas Gregor29c42f22012-02-24 07:38:34 +00009817 TypeLocBuilder TLB;
9818 TLB.reserve(From->getTypeLoc().getFullDataSize());
9819
9820 QualType To = getDerived().TransformType(TLB, PatternTL);
9821 if (To.isNull())
9822 return ExprError();
9823
Chad Rosier1dcde962012-08-08 18:46:20 +00009824 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009825 PatternTL.getSourceRange(),
9826 ExpansionTL.getEllipsisLoc(),
9827 NumExpansions);
9828 if (To.isNull())
9829 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009830
Douglas Gregor29c42f22012-02-24 07:38:34 +00009831 PackExpansionTypeLoc ToExpansionTL
9832 = TLB.push<PackExpansionTypeLoc>(To);
9833 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9834 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9835 continue;
9836 }
9837
9838 // Expand the pack expansion by substituting for each argument in the
9839 // pack(s).
9840 for (unsigned I = 0; I != *NumExpansions; ++I) {
9841 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9842 TypeLocBuilder TLB;
9843 TLB.reserve(PatternTL.getFullDataSize());
9844 QualType To = getDerived().TransformType(TLB, PatternTL);
9845 if (To.isNull())
9846 return ExprError();
9847
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009848 if (To->containsUnexpandedParameterPack()) {
9849 To = getDerived().RebuildPackExpansionType(To,
9850 PatternTL.getSourceRange(),
9851 ExpansionTL.getEllipsisLoc(),
9852 NumExpansions);
9853 if (To.isNull())
9854 return ExprError();
9855
9856 PackExpansionTypeLoc ToExpansionTL
9857 = TLB.push<PackExpansionTypeLoc>(To);
9858 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9859 }
9860
Douglas Gregor29c42f22012-02-24 07:38:34 +00009861 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009863
Douglas Gregor29c42f22012-02-24 07:38:34 +00009864 if (!RetainExpansion)
9865 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009866
Douglas Gregor29c42f22012-02-24 07:38:34 +00009867 // If we're supposed to retain a pack expansion, do so by temporarily
9868 // forgetting the partially-substituted parameter pack.
9869 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9870
9871 TypeLocBuilder TLB;
9872 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009873
Douglas Gregor29c42f22012-02-24 07:38:34 +00009874 QualType To = getDerived().TransformType(TLB, PatternTL);
9875 if (To.isNull())
9876 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009877
9878 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009879 PatternTL.getSourceRange(),
9880 ExpansionTL.getEllipsisLoc(),
9881 NumExpansions);
9882 if (To.isNull())
9883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009884
Douglas Gregor29c42f22012-02-24 07:38:34 +00009885 PackExpansionTypeLoc ToExpansionTL
9886 = TLB.push<PackExpansionTypeLoc>(To);
9887 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9888 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009890
Douglas Gregor29c42f22012-02-24 07:38:34 +00009891 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009892 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009893
9894 return getDerived().RebuildTypeTrait(E->getTrait(),
9895 E->getLocStart(),
9896 Args,
9897 E->getLocEnd());
9898}
9899
9900template<typename Derived>
9901ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009902TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9903 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9904 if (!T)
9905 return ExprError();
9906
9907 if (!getDerived().AlwaysRebuild() &&
9908 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009909 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009910
9911 ExprResult SubExpr;
9912 {
9913 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9914 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9915 if (SubExpr.isInvalid())
9916 return ExprError();
9917
9918 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009919 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009920 }
9921
9922 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9923 E->getLocStart(),
9924 T,
9925 SubExpr.get(),
9926 E->getLocEnd());
9927}
9928
9929template<typename Derived>
9930ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009931TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9932 ExprResult SubExpr;
9933 {
9934 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9935 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9936 if (SubExpr.isInvalid())
9937 return ExprError();
9938
9939 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009940 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009941 }
9942
9943 return getDerived().RebuildExpressionTrait(
9944 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9945}
9946
Reid Kleckner32506ed2014-06-12 23:03:48 +00009947template <typename Derived>
9948ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9949 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9950 TypeSourceInfo **RecoveryTSI) {
9951 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9952 DRE, AddrTaken, RecoveryTSI);
9953
9954 // Propagate both errors and recovered types, which return ExprEmpty.
9955 if (!NewDRE.isUsable())
9956 return NewDRE;
9957
9958 // We got an expr, wrap it up in parens.
9959 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9960 return PE;
9961 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9962 PE->getRParen());
9963}
9964
9965template <typename Derived>
9966ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9967 DependentScopeDeclRefExpr *E) {
9968 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9969 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009970}
9971
9972template<typename Derived>
9973ExprResult
9974TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9975 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009976 bool IsAddressOfOperand,
9977 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009978 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009979 NestedNameSpecifierLoc QualifierLoc
9980 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9981 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009982 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009983 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009984
John McCall31f82722010-11-12 08:19:04 +00009985 // TODO: If this is a conversion-function-id, verify that the
9986 // destination type name (if present) resolves the same way after
9987 // instantiation as it did in the local scope.
9988
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009989 DeclarationNameInfo NameInfo
9990 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9991 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009993
John McCalle66edc12009-11-24 19:00:30 +00009994 if (!E->hasExplicitTemplateArgs()) {
9995 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009996 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009997 // Note: it is sufficient to compare the Name component of NameInfo:
9998 // if name has not changed, DNLoc has not changed either.
9999 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010000 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010001
Reid Kleckner32506ed2014-06-12 23:03:48 +000010002 return getDerived().RebuildDependentScopeDeclRefExpr(
10003 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10004 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010005 }
John McCall6b51f282009-11-23 01:53:49 +000010006
10007 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010008 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10009 E->getNumTemplateArgs(),
10010 TransArgs))
10011 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010012
Reid Kleckner32506ed2014-06-12 23:03:48 +000010013 return getDerived().RebuildDependentScopeDeclRefExpr(
10014 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10015 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010016}
10017
10018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010020TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010021 // CXXConstructExprs other than for list-initialization and
10022 // CXXTemporaryObjectExpr are always implicit, so when we have
10023 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010024 if ((E->getNumArgs() == 1 ||
10025 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010026 (!getDerived().DropCallArgument(E->getArg(0))) &&
10027 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010028 return getDerived().TransformExpr(E->getArg(0));
10029
Douglas Gregora16548e2009-08-11 05:31:07 +000010030 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10031
10032 QualType T = getDerived().TransformType(E->getType());
10033 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010034 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010035
10036 CXXConstructorDecl *Constructor
10037 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010038 getDerived().TransformDecl(E->getLocStart(),
10039 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010040 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010042
Douglas Gregora16548e2009-08-11 05:31:07 +000010043 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010044 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010045 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010046 &ArgumentChanged))
10047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010048
Douglas Gregora16548e2009-08-11 05:31:07 +000010049 if (!getDerived().AlwaysRebuild() &&
10050 T == E->getType() &&
10051 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010052 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010053 // Mark the constructor as referenced.
10054 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010055 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010056 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010057 }
Mike Stump11289f42009-09-09 15:08:12 +000010058
Douglas Gregordb121ba2009-12-14 16:27:04 +000010059 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010060 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010061 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010062 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010063 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010064 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010065 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010066 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010067 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010068}
Mike Stump11289f42009-09-09 15:08:12 +000010069
Richard Smith5179eb72016-06-28 19:03:57 +000010070template<typename Derived>
10071ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10072 CXXInheritedCtorInitExpr *E) {
10073 QualType T = getDerived().TransformType(E->getType());
10074 if (T.isNull())
10075 return ExprError();
10076
10077 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10078 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10079 if (!Constructor)
10080 return ExprError();
10081
10082 if (!getDerived().AlwaysRebuild() &&
10083 T == E->getType() &&
10084 Constructor == E->getConstructor()) {
10085 // Mark the constructor as referenced.
10086 // FIXME: Instantiation-specific
10087 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10088 return E;
10089 }
10090
10091 return getDerived().RebuildCXXInheritedCtorInitExpr(
10092 T, E->getLocation(), Constructor,
10093 E->constructsVBase(), E->inheritedFromVBase());
10094}
10095
Douglas Gregora16548e2009-08-11 05:31:07 +000010096/// \brief Transform a C++ temporary-binding expression.
10097///
Douglas Gregor363b1512009-12-24 18:51:59 +000010098/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10099/// 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 McCall47f29ea2009-12-08 09:21:05 +000010102TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *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
John McCall5d413782010-12-06 08:20:24 +000010106/// \brief Transform a C++ expression that contains cleanups that should
10107/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010108///
John McCall5d413782010-12-06 08:20:24 +000010109/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010110/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010112ExprResult
John McCall5d413782010-12-06 08:20:24 +000010113TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010114 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010115}
Mike Stump11289f42009-09-09 15:08:12 +000010116
Douglas Gregora16548e2009-08-11 05:31:07 +000010117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010118ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010119TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010120 CXXTemporaryObjectExpr *E) {
10121 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10122 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010124
Douglas Gregora16548e2009-08-11 05:31:07 +000010125 CXXConstructorDecl *Constructor
10126 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010127 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010128 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010129 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010131
Douglas Gregora16548e2009-08-11 05:31:07 +000010132 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010133 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010134 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010135 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010136 &ArgumentChanged))
10137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010138
Douglas Gregora16548e2009-08-11 05:31:07 +000010139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010140 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010141 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010142 !ArgumentChanged) {
10143 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010144 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010145 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010146 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010147
Richard Smithd59b8322012-12-19 01:39:02 +000010148 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010149 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10150 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010151 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010152 E->getLocEnd());
10153}
Mike Stump11289f42009-09-09 15:08:12 +000010154
Douglas Gregora16548e2009-08-11 05:31:07 +000010155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010156ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010157TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010158 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010159 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010160 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010161 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10162 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010163 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010164 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010165 CEnd = E->capture_end();
10166 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010167 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010168 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010169 EnterExpressionEvaluationContext EEEC(getSema(),
10170 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010171 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10172 C->getCapturedVar()->getInit(),
10173 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010174
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010175 if (NewExprInitResult.isInvalid())
10176 return ExprError();
10177 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010178
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010179 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010180 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010181 getSema().buildLambdaInitCaptureInitialization(
10182 C->getLocation(), OldVD->getType()->isReferenceType(),
10183 OldVD->getIdentifier(),
10184 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010185 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010186 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10187 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010188 }
10189
Faisal Vali2cba1332013-10-23 06:44:28 +000010190 // Transform the template parameters, and add them to the current
10191 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010192 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010193 E->getTemplateParameterList());
10194
Richard Smith01014ce2014-11-20 23:53:14 +000010195 // Transform the type of the original lambda's call operator.
10196 // The transformation MUST be done in the CurrentInstantiationScope since
10197 // it introduces a mapping of the original to the newly created
10198 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010199 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010200 {
10201 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10202 FunctionProtoTypeLoc OldCallOpFPTL =
10203 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010204
10205 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010206 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010207 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010208 QualType NewCallOpType = TransformFunctionProtoType(
10209 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010210 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10211 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10212 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010213 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010214 if (NewCallOpType.isNull())
10215 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010216 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10217 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010218 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010219
Richard Smithc38498f2015-04-27 21:27:54 +000010220 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10221 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10222 LSI->GLTemplateParameterList = TPL;
10223
Eli Friedmand564afb2012-09-19 01:18:11 +000010224 // Create the local class that will describe the lambda.
10225 CXXRecordDecl *Class
10226 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010227 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010228 /*KnownDependent=*/false,
10229 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010230 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10231
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010232 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010233 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10234 Class, E->getIntroducerRange(), NewCallOpTSI,
10235 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010236 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10237 E->getCallOperator()->isConstexpr());
10238
Faisal Vali2cba1332013-10-23 06:44:28 +000010239 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010240
Faisal Vali2cba1332013-10-23 06:44:28 +000010241 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010242 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010243
Douglas Gregorb4328232012-02-14 00:00:48 +000010244 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010245 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010246 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010247
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010248 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010249 getSema().buildLambdaScope(LSI, NewCallOperator,
10250 E->getIntroducerRange(),
10251 E->getCaptureDefault(),
10252 E->getCaptureDefaultLoc(),
10253 E->hasExplicitParameters(),
10254 E->hasExplicitResultType(),
10255 E->isMutable());
10256
10257 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010258
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010259 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010260 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010261 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010262 CEnd = E->capture_end();
10263 C != CEnd; ++C) {
10264 // When we hit the first implicit capture, tell Sema that we've finished
10265 // the list of explicit captures.
10266 if (!FinishedExplicitCaptures && C->isImplicit()) {
10267 getSema().finishLambdaExplicitCaptures(LSI);
10268 FinishedExplicitCaptures = true;
10269 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010270
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010271 // Capturing 'this' is trivial.
10272 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010273 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10274 /*BuildAndDiagnose*/ true, nullptr,
10275 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010276 continue;
10277 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010278 // Captured expression will be recaptured during captured variables
10279 // rebuilding.
10280 if (C->capturesVLAType())
10281 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010282
Richard Smithba71c082013-05-16 06:20:58 +000010283 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010284 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010285 InitCaptureInfoTy InitExprTypePair =
10286 InitCaptureExprsAndTypes[C - E->capture_begin()];
10287 ExprResult Init = InitExprTypePair.first;
10288 QualType InitQualType = InitExprTypePair.second;
10289 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010290 Invalid = true;
10291 continue;
10292 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010293 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010294 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010295 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10296 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010297 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010298 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010299 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010300 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010301 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010302 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010303 continue;
10304 }
10305
10306 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10307
Douglas Gregor3e308b12012-02-14 19:27:52 +000010308 // Determine the capture kind for Sema.
10309 Sema::TryCaptureKind Kind
10310 = C->isImplicit()? Sema::TryCapture_Implicit
10311 : C->getCaptureKind() == LCK_ByCopy
10312 ? Sema::TryCapture_ExplicitByVal
10313 : Sema::TryCapture_ExplicitByRef;
10314 SourceLocation EllipsisLoc;
10315 if (C->isPackExpansion()) {
10316 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10317 bool ShouldExpand = false;
10318 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010319 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010320 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10321 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010322 Unexpanded,
10323 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010324 NumExpansions)) {
10325 Invalid = true;
10326 continue;
10327 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010328
Douglas Gregor3e308b12012-02-14 19:27:52 +000010329 if (ShouldExpand) {
10330 // The transform has determined that we should perform an expansion;
10331 // transform and capture each of the arguments.
10332 // expansion of the pattern. Do so.
10333 VarDecl *Pack = C->getCapturedVar();
10334 for (unsigned I = 0; I != *NumExpansions; ++I) {
10335 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10336 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010337 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010338 Pack));
10339 if (!CapturedVar) {
10340 Invalid = true;
10341 continue;
10342 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010343
Douglas Gregor3e308b12012-02-14 19:27:52 +000010344 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010345 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10346 }
Richard Smith9467be42014-06-06 17:33:35 +000010347
10348 // FIXME: Retain a pack expansion if RetainExpansion is true.
10349
Douglas Gregor3e308b12012-02-14 19:27:52 +000010350 continue;
10351 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010352
Douglas Gregor3e308b12012-02-14 19:27:52 +000010353 EllipsisLoc = C->getEllipsisLoc();
10354 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010355
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010356 // Transform the captured variable.
10357 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010358 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010359 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010360 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010361 Invalid = true;
10362 continue;
10363 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010364
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010365 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010366 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10367 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010368 }
10369 if (!FinishedExplicitCaptures)
10370 getSema().finishLambdaExplicitCaptures(LSI);
10371
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010372 // Enter a new evaluation context to insulate the lambda from any
10373 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010374 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010375
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010376 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010377 StmtResult Body =
10378 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10379
10380 // ActOnLambda* will pop the function scope for us.
10381 FuncScopeCleanup.disable();
10382
Douglas Gregorb4328232012-02-14 00:00:48 +000010383 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010384 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010385 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010386 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010387 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010388 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010389
Richard Smithc38498f2015-04-27 21:27:54 +000010390 // Copy the LSI before ActOnFinishFunctionBody removes it.
10391 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10392 // the call operator.
10393 auto LSICopy = *LSI;
10394 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10395 /*IsInstantiation*/ true);
10396 SavedContext.pop();
10397
10398 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10399 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010400}
10401
10402template<typename Derived>
10403ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010404TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010405 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010406 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10407 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010409
Douglas Gregora16548e2009-08-11 05:31:07 +000010410 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010411 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010412 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010413 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010414 &ArgumentChanged))
10415 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010416
Douglas Gregora16548e2009-08-11 05:31:07 +000010417 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010418 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010419 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010420 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010421
Douglas Gregora16548e2009-08-11 05:31:07 +000010422 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010423 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010424 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010425 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010426 E->getRParenLoc());
10427}
Mike Stump11289f42009-09-09 15:08:12 +000010428
Douglas Gregora16548e2009-08-11 05:31:07 +000010429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010430ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010431TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010432 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010433 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010434 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010435 Expr *OldBase;
10436 QualType BaseType;
10437 QualType ObjectType;
10438 if (!E->isImplicitAccess()) {
10439 OldBase = E->getBase();
10440 Base = getDerived().TransformExpr(OldBase);
10441 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010443
John McCall2d74de92009-12-01 22:10:20 +000010444 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010445 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010446 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010447 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010448 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010449 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010450 ObjectTy,
10451 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010452 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010453 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010454
John McCallba7bf592010-08-24 05:47:05 +000010455 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010456 BaseType = ((Expr*) Base.get())->getType();
10457 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010458 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010459 BaseType = getDerived().TransformType(E->getBaseType());
10460 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10461 }
Mike Stump11289f42009-09-09 15:08:12 +000010462
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010463 // Transform the first part of the nested-name-specifier that qualifies
10464 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010465 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010466 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010467 E->getFirstQualifierFoundInScope(),
10468 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010469
Douglas Gregore16af532011-02-28 18:50:33 +000010470 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010471 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010472 QualifierLoc
10473 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10474 ObjectType,
10475 FirstQualifierInScope);
10476 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010477 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010478 }
Mike Stump11289f42009-09-09 15:08:12 +000010479
Abramo Bagnara7945c982012-01-27 09:46:47 +000010480 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10481
John McCall31f82722010-11-12 08:19:04 +000010482 // TODO: If this is a conversion-function-id, verify that the
10483 // destination type name (if present) resolves the same way after
10484 // instantiation as it did in the local scope.
10485
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010486 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010487 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010488 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010490
John McCall2d74de92009-12-01 22:10:20 +000010491 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010492 // This is a reference to a member without an explicitly-specified
10493 // template argument list. Optimize for this common case.
10494 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010495 Base.get() == OldBase &&
10496 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010497 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010498 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010499 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010500 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010501
John McCallb268a282010-08-23 23:25:46 +000010502 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010503 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010504 E->isArrow(),
10505 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010506 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010507 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010508 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010509 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010510 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010511 }
10512
John McCall6b51f282009-11-23 01:53:49 +000010513 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010514 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10515 E->getNumTemplateArgs(),
10516 TransArgs))
10517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010518
John McCallb268a282010-08-23 23:25:46 +000010519 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010520 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010521 E->isArrow(),
10522 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010523 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010524 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010525 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010526 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010527 &TransArgs);
10528}
10529
10530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010532TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010533 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010534 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010535 QualType BaseType;
10536 if (!Old->isImplicitAccess()) {
10537 Base = getDerived().TransformExpr(Old->getBase());
10538 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010539 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010540 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010541 Old->isArrow());
10542 if (Base.isInvalid())
10543 return ExprError();
10544 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010545 } else {
10546 BaseType = getDerived().TransformType(Old->getBaseType());
10547 }
John McCall10eae182009-11-30 22:42:35 +000010548
Douglas Gregor0da1d432011-02-28 20:01:57 +000010549 NestedNameSpecifierLoc QualifierLoc;
10550 if (Old->getQualifierLoc()) {
10551 QualifierLoc
10552 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10553 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010554 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010555 }
10556
Abramo Bagnara7945c982012-01-27 09:46:47 +000010557 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10558
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010559 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010560 Sema::LookupOrdinaryName);
10561
10562 // Transform all the decls.
10563 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10564 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010565 NamedDecl *InstD = static_cast<NamedDecl*>(
10566 getDerived().TransformDecl(Old->getMemberLoc(),
10567 *I));
John McCall84d87672009-12-10 09:41:52 +000010568 if (!InstD) {
10569 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10570 // This can happen because of dependent hiding.
10571 if (isa<UsingShadowDecl>(*I))
10572 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010573 else {
10574 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010575 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010576 }
John McCall84d87672009-12-10 09:41:52 +000010577 }
John McCall10eae182009-11-30 22:42:35 +000010578
10579 // Expand using declarations.
10580 if (isa<UsingDecl>(InstD)) {
10581 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010582 for (auto *I : UD->shadows())
10583 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010584 continue;
10585 }
10586
10587 R.addDecl(InstD);
10588 }
10589
10590 R.resolveKind();
10591
Douglas Gregor9262f472010-04-27 18:19:34 +000010592 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010593 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010594 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010595 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010596 Old->getMemberLoc(),
10597 Old->getNamingClass()));
10598 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010599 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010600
Douglas Gregorda7be082010-04-27 16:10:10 +000010601 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010602 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010603
John McCall10eae182009-11-30 22:42:35 +000010604 TemplateArgumentListInfo TransArgs;
10605 if (Old->hasExplicitTemplateArgs()) {
10606 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10607 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010608 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10609 Old->getNumTemplateArgs(),
10610 TransArgs))
10611 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010612 }
John McCall38836f02010-01-15 08:34:02 +000010613
10614 // FIXME: to do this check properly, we will need to preserve the
10615 // first-qualifier-in-scope here, just in case we had a dependent
10616 // base (and therefore couldn't do the check) and a
10617 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010618 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010619
John McCallb268a282010-08-23 23:25:46 +000010620 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010621 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010622 Old->getOperatorLoc(),
10623 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010624 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010625 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010626 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010627 R,
10628 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010629 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010630}
10631
10632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010633ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010634TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010636 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10637 if (SubExpr.isInvalid())
10638 return ExprError();
10639
10640 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010641 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010642
10643 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10644}
10645
10646template<typename Derived>
10647ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010648TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010649 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10650 if (Pattern.isInvalid())
10651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010652
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010653 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010654 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010655
Douglas Gregorb8840002011-01-14 21:20:45 +000010656 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10657 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010658}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010659
10660template<typename Derived>
10661ExprResult
10662TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10663 // If E is not value-dependent, then nothing will change when we transform it.
10664 // Note: This is an instantiation-centric view.
10665 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010666 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010667
Richard Smithd784e682015-09-23 21:41:42 +000010668 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010669
Richard Smithd784e682015-09-23 21:41:42 +000010670 ArrayRef<TemplateArgument> PackArgs;
10671 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010672
Richard Smithd784e682015-09-23 21:41:42 +000010673 // Find the argument list to transform.
10674 if (E->isPartiallySubstituted()) {
10675 PackArgs = E->getPartialArguments();
10676 } else if (E->isValueDependent()) {
10677 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10678 bool ShouldExpand = false;
10679 bool RetainExpansion = false;
10680 Optional<unsigned> NumExpansions;
10681 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10682 Unexpanded,
10683 ShouldExpand, RetainExpansion,
10684 NumExpansions))
10685 return ExprError();
10686
10687 // If we need to expand the pack, build a template argument from it and
10688 // expand that.
10689 if (ShouldExpand) {
10690 auto *Pack = E->getPack();
10691 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10692 ArgStorage = getSema().Context.getPackExpansionType(
10693 getSema().Context.getTypeDeclType(TTPD), None);
10694 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10695 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10696 } else {
10697 auto *VD = cast<ValueDecl>(Pack);
10698 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10699 VK_RValue, E->getPackLoc());
10700 if (DRE.isInvalid())
10701 return ExprError();
10702 ArgStorage = new (getSema().Context) PackExpansionExpr(
10703 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10704 }
10705 PackArgs = ArgStorage;
10706 }
10707 }
10708
10709 // If we're not expanding the pack, just transform the decl.
10710 if (!PackArgs.size()) {
10711 auto *Pack = cast_or_null<NamedDecl>(
10712 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010713 if (!Pack)
10714 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010715 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10716 E->getPackLoc(),
10717 E->getRParenLoc(), None, None);
10718 }
10719
10720 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10721 E->getPackLoc());
10722 {
10723 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10724 typedef TemplateArgumentLocInventIterator<
10725 Derived, const TemplateArgument*> PackLocIterator;
10726 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10727 PackLocIterator(*this, PackArgs.end()),
10728 TransformedPackArgs, /*Uneval*/true))
10729 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010730 }
10731
Richard Smithd784e682015-09-23 21:41:42 +000010732 SmallVector<TemplateArgument, 8> Args;
10733 bool PartialSubstitution = false;
10734 for (auto &Loc : TransformedPackArgs.arguments()) {
10735 Args.push_back(Loc.getArgument());
10736 if (Loc.getArgument().isPackExpansion())
10737 PartialSubstitution = true;
10738 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010739
Richard Smithd784e682015-09-23 21:41:42 +000010740 if (PartialSubstitution)
10741 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10742 E->getPackLoc(),
10743 E->getRParenLoc(), None, Args);
10744
10745 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010746 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010747 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010748}
10749
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010750template<typename Derived>
10751ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010752TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10753 SubstNonTypeTemplateParmPackExpr *E) {
10754 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010755 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010756}
10757
10758template<typename Derived>
10759ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010760TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10761 SubstNonTypeTemplateParmExpr *E) {
10762 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010763 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010764}
10765
10766template<typename Derived>
10767ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010768TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10769 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010770 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010771}
10772
10773template<typename Derived>
10774ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010775TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10776 MaterializeTemporaryExpr *E) {
10777 return getDerived().TransformExpr(E->GetTemporaryExpr());
10778}
Chad Rosier1dcde962012-08-08 18:46:20 +000010779
Douglas Gregorfe314812011-06-21 17:03:29 +000010780template<typename Derived>
10781ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010782TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10783 Expr *Pattern = E->getPattern();
10784
10785 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10786 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10787 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10788
10789 // Determine whether the set of unexpanded parameter packs can and should
10790 // be expanded.
10791 bool Expand = true;
10792 bool RetainExpansion = false;
10793 Optional<unsigned> NumExpansions;
10794 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10795 Pattern->getSourceRange(),
10796 Unexpanded,
10797 Expand, RetainExpansion,
10798 NumExpansions))
10799 return true;
10800
10801 if (!Expand) {
10802 // Do not expand any packs here, just transform and rebuild a fold
10803 // expression.
10804 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10805
10806 ExprResult LHS =
10807 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10808 if (LHS.isInvalid())
10809 return true;
10810
10811 ExprResult RHS =
10812 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10813 if (RHS.isInvalid())
10814 return true;
10815
10816 if (!getDerived().AlwaysRebuild() &&
10817 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10818 return E;
10819
10820 return getDerived().RebuildCXXFoldExpr(
10821 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10822 RHS.get(), E->getLocEnd());
10823 }
10824
10825 // The transform has determined that we should perform an elementwise
10826 // expansion of the pattern. Do so.
10827 ExprResult Result = getDerived().TransformExpr(E->getInit());
10828 if (Result.isInvalid())
10829 return true;
10830 bool LeftFold = E->isLeftFold();
10831
10832 // If we're retaining an expansion for a right fold, it is the innermost
10833 // component and takes the init (if any).
10834 if (!LeftFold && RetainExpansion) {
10835 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10836
10837 ExprResult Out = getDerived().TransformExpr(Pattern);
10838 if (Out.isInvalid())
10839 return true;
10840
10841 Result = getDerived().RebuildCXXFoldExpr(
10842 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10843 Result.get(), E->getLocEnd());
10844 if (Result.isInvalid())
10845 return true;
10846 }
10847
10848 for (unsigned I = 0; I != *NumExpansions; ++I) {
10849 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10850 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10851 ExprResult Out = getDerived().TransformExpr(Pattern);
10852 if (Out.isInvalid())
10853 return true;
10854
10855 if (Out.get()->containsUnexpandedParameterPack()) {
10856 // We still have a pack; retain a pack expansion for this slice.
10857 Result = getDerived().RebuildCXXFoldExpr(
10858 E->getLocStart(),
10859 LeftFold ? Result.get() : Out.get(),
10860 E->getOperator(), E->getEllipsisLoc(),
10861 LeftFold ? Out.get() : Result.get(),
10862 E->getLocEnd());
10863 } else if (Result.isUsable()) {
10864 // We've got down to a single element; build a binary operator.
10865 Result = getDerived().RebuildBinaryOperator(
10866 E->getEllipsisLoc(), E->getOperator(),
10867 LeftFold ? Result.get() : Out.get(),
10868 LeftFold ? Out.get() : Result.get());
10869 } else
10870 Result = Out;
10871
10872 if (Result.isInvalid())
10873 return true;
10874 }
10875
10876 // If we're retaining an expansion for a left fold, it is the outermost
10877 // component and takes the complete expansion so far as its init (if any).
10878 if (LeftFold && RetainExpansion) {
10879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10880
10881 ExprResult Out = getDerived().TransformExpr(Pattern);
10882 if (Out.isInvalid())
10883 return true;
10884
10885 Result = getDerived().RebuildCXXFoldExpr(
10886 E->getLocStart(), Result.get(),
10887 E->getOperator(), E->getEllipsisLoc(),
10888 Out.get(), E->getLocEnd());
10889 if (Result.isInvalid())
10890 return true;
10891 }
10892
10893 // If we had no init and an empty pack, and we're not retaining an expansion,
10894 // then produce a fallback value or error.
10895 if (Result.isUnset())
10896 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10897 E->getOperator());
10898
10899 return Result;
10900}
10901
10902template<typename Derived>
10903ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010904TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10905 CXXStdInitializerListExpr *E) {
10906 return getDerived().TransformExpr(E->getSubExpr());
10907}
10908
10909template<typename Derived>
10910ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010911TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010912 return SemaRef.MaybeBindToTemporary(E);
10913}
10914
10915template<typename Derived>
10916ExprResult
10917TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010918 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010919}
10920
10921template<typename Derived>
10922ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010923TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10924 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10925 if (SubExpr.isInvalid())
10926 return ExprError();
10927
10928 if (!getDerived().AlwaysRebuild() &&
10929 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010930 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010931
10932 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010933}
10934
10935template<typename Derived>
10936ExprResult
10937TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10938 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010939 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010940 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010941 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010942 /*IsCall=*/false, Elements, &ArgChanged))
10943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010944
Ted Kremeneke65b0862012-03-06 20:05:56 +000010945 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10946 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010947
Ted Kremeneke65b0862012-03-06 20:05:56 +000010948 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10949 Elements.data(),
10950 Elements.size());
10951}
10952
10953template<typename Derived>
10954ExprResult
10955TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010956 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010957 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010958 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010959 bool ArgChanged = false;
10960 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10961 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
Ted Kremeneke65b0862012-03-06 20:05:56 +000010963 if (OrigElement.isPackExpansion()) {
10964 // This key/value element is a pack expansion.
10965 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10966 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10967 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10968 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10969
10970 // Determine whether the set of unexpanded parameter packs can
10971 // and should be expanded.
10972 bool Expand = true;
10973 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010974 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10975 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010976 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10977 OrigElement.Value->getLocEnd());
10978 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10979 PatternRange,
10980 Unexpanded,
10981 Expand, RetainExpansion,
10982 NumExpansions))
10983 return ExprError();
10984
10985 if (!Expand) {
10986 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010987 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010988 // expansion.
10989 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10990 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10991 if (Key.isInvalid())
10992 return ExprError();
10993
10994 if (Key.get() != OrigElement.Key)
10995 ArgChanged = true;
10996
10997 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10998 if (Value.isInvalid())
10999 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011000
Ted Kremeneke65b0862012-03-06 20:05:56 +000011001 if (Value.get() != OrigElement.Value)
11002 ArgChanged = true;
11003
Chad Rosier1dcde962012-08-08 18:46:20 +000011004 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011005 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11006 };
11007 Elements.push_back(Expansion);
11008 continue;
11009 }
11010
11011 // Record right away that the argument was changed. This needs
11012 // to happen even if the array expands to nothing.
11013 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011014
Ted Kremeneke65b0862012-03-06 20:05:56 +000011015 // The transform has determined that we should perform an elementwise
11016 // expansion of the pattern. Do so.
11017 for (unsigned I = 0; I != *NumExpansions; ++I) {
11018 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11019 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11020 if (Key.isInvalid())
11021 return ExprError();
11022
11023 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11024 if (Value.isInvalid())
11025 return ExprError();
11026
Chad Rosier1dcde962012-08-08 18:46:20 +000011027 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011028 Key.get(), Value.get(), SourceLocation(), NumExpansions
11029 };
11030
11031 // If any unexpanded parameter packs remain, we still have a
11032 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011033 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011034 if (Key.get()->containsUnexpandedParameterPack() ||
11035 Value.get()->containsUnexpandedParameterPack())
11036 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011037
Ted Kremeneke65b0862012-03-06 20:05:56 +000011038 Elements.push_back(Element);
11039 }
11040
Richard Smith9467be42014-06-06 17:33:35 +000011041 // FIXME: Retain a pack expansion if RetainExpansion is true.
11042
Ted Kremeneke65b0862012-03-06 20:05:56 +000011043 // We've finished with this pack expansion.
11044 continue;
11045 }
11046
11047 // Transform and check key.
11048 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11049 if (Key.isInvalid())
11050 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011051
Ted Kremeneke65b0862012-03-06 20:05:56 +000011052 if (Key.get() != OrigElement.Key)
11053 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011054
Ted Kremeneke65b0862012-03-06 20:05:56 +000011055 // Transform and check value.
11056 ExprResult Value
11057 = getDerived().TransformExpr(OrigElement.Value);
11058 if (Value.isInvalid())
11059 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011060
Ted Kremeneke65b0862012-03-06 20:05:56 +000011061 if (Value.get() != OrigElement.Value)
11062 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011063
11064 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011065 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011066 };
11067 Elements.push_back(Element);
11068 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011069
Ted Kremeneke65b0862012-03-06 20:05:56 +000011070 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11071 return SemaRef.MaybeBindToTemporary(E);
11072
11073 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011074 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011075}
11076
Mike Stump11289f42009-09-09 15:08:12 +000011077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011079TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011080 TypeSourceInfo *EncodedTypeInfo
11081 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11082 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011084
Douglas Gregora16548e2009-08-11 05:31:07 +000011085 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011086 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011087 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011088
11089 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011090 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011091 E->getRParenLoc());
11092}
Mike Stump11289f42009-09-09 15:08:12 +000011093
Douglas Gregora16548e2009-08-11 05:31:07 +000011094template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011095ExprResult TreeTransform<Derived>::
11096TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011097 // This is a kind of implicit conversion, and it needs to get dropped
11098 // and recomputed for the same general reasons that ImplicitCastExprs
11099 // do, as well a more specific one: this expression is only valid when
11100 // it appears *immediately* as an argument expression.
11101 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011102}
11103
11104template<typename Derived>
11105ExprResult TreeTransform<Derived>::
11106TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011107 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011108 = getDerived().TransformType(E->getTypeInfoAsWritten());
11109 if (!TSInfo)
11110 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011111
John McCall31168b02011-06-15 23:02:42 +000011112 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011113 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011114 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011115
John McCall31168b02011-06-15 23:02:42 +000011116 if (!getDerived().AlwaysRebuild() &&
11117 TSInfo == E->getTypeInfoAsWritten() &&
11118 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011119 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011120
John McCall31168b02011-06-15 23:02:42 +000011121 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011122 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011123 Result.get());
11124}
11125
Erik Pilkington29099de2016-07-16 00:35:23 +000011126template <typename Derived>
11127ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11128 ObjCAvailabilityCheckExpr *E) {
11129 return E;
11130}
11131
John McCall31168b02011-06-15 23:02:42 +000011132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011134TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011135 // Transform arguments.
11136 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011137 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011138 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011139 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011140 &ArgChanged))
11141 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011142
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011143 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11144 // Class message: transform the receiver type.
11145 TypeSourceInfo *ReceiverTypeInfo
11146 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11147 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011148 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011149
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011150 // If nothing changed, just retain the existing message send.
11151 if (!getDerived().AlwaysRebuild() &&
11152 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011153 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011154
11155 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011156 SmallVector<SourceLocation, 16> SelLocs;
11157 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011158 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11159 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011160 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011161 E->getMethodDecl(),
11162 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011163 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011164 E->getRightLoc());
11165 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011166 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11167 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11168 // Build a new class message send to 'super'.
11169 SmallVector<SourceLocation, 16> SelLocs;
11170 E->getSelectorLocs(SelLocs);
11171 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11172 E->getSelector(),
11173 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011174 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011175 E->getMethodDecl(),
11176 E->getLeftLoc(),
11177 Args,
11178 E->getRightLoc());
11179 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011180
11181 // Instance message: transform the receiver
11182 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11183 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011184 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011185 = getDerived().TransformExpr(E->getInstanceReceiver());
11186 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011187 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011188
11189 // If nothing changed, just retain the existing message send.
11190 if (!getDerived().AlwaysRebuild() &&
11191 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011192 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011193
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011194 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011195 SmallVector<SourceLocation, 16> SelLocs;
11196 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011197 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011198 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011199 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011200 E->getMethodDecl(),
11201 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011202 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011203 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011204}
11205
Mike Stump11289f42009-09-09 15:08:12 +000011206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011208TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011209 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011210}
11211
Mike Stump11289f42009-09-09 15:08:12 +000011212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011214TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011215 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011216}
11217
Mike Stump11289f42009-09-09 15:08:12 +000011218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011220TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011221 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011222 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011223 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011224 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011225
11226 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011227
Douglas Gregord51d90d2010-04-26 20:11:03 +000011228 // If nothing changed, just retain the existing expression.
11229 if (!getDerived().AlwaysRebuild() &&
11230 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011231 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011232
John McCallb268a282010-08-23 23:25:46 +000011233 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011234 E->getLocation(),
11235 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011236}
11237
Mike Stump11289f42009-09-09 15:08:12 +000011238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011240TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011241 // 'super' and types never change. Property never changes. Just
11242 // retain the existing expression.
11243 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011244 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011245
Douglas Gregor9faee212010-04-26 20:47:02 +000011246 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011247 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011248 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011249 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011250
Douglas Gregor9faee212010-04-26 20:47:02 +000011251 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011252
Douglas Gregor9faee212010-04-26 20:47:02 +000011253 // If nothing changed, just retain the existing expression.
11254 if (!getDerived().AlwaysRebuild() &&
11255 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011256 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011257
John McCallb7bd14f2010-12-02 01:19:52 +000011258 if (E->isExplicitProperty())
11259 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11260 E->getExplicitProperty(),
11261 E->getLocation());
11262
11263 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011264 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011265 E->getImplicitPropertyGetter(),
11266 E->getImplicitPropertySetter(),
11267 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011268}
11269
Mike Stump11289f42009-09-09 15:08:12 +000011270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011271ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011272TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11273 // Transform the base expression.
11274 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11275 if (Base.isInvalid())
11276 return ExprError();
11277
11278 // Transform the key expression.
11279 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11280 if (Key.isInvalid())
11281 return ExprError();
11282
11283 // If nothing changed, just retain the existing expression.
11284 if (!getDerived().AlwaysRebuild() &&
11285 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011286 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011287
Chad Rosier1dcde962012-08-08 18:46:20 +000011288 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011289 Base.get(), Key.get(),
11290 E->getAtIndexMethodDecl(),
11291 E->setAtIndexMethodDecl());
11292}
11293
11294template<typename Derived>
11295ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011296TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011297 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011298 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011299 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011301
Douglas Gregord51d90d2010-04-26 20:11:03 +000011302 // If nothing changed, just retain the existing expression.
11303 if (!getDerived().AlwaysRebuild() &&
11304 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011305 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011306
John McCallb268a282010-08-23 23:25:46 +000011307 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011308 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011309 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011310}
11311
Mike Stump11289f42009-09-09 15:08:12 +000011312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011314TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011315 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011316 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011317 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011318 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011319 SubExprs, &ArgumentChanged))
11320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011321
Douglas Gregora16548e2009-08-11 05:31:07 +000011322 if (!getDerived().AlwaysRebuild() &&
11323 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011324 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011325
Douglas Gregora16548e2009-08-11 05:31:07 +000011326 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011327 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011328 E->getRParenLoc());
11329}
11330
Mike Stump11289f42009-09-09 15:08:12 +000011331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011332ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011333TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11334 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11335 if (SrcExpr.isInvalid())
11336 return ExprError();
11337
11338 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11339 if (!Type)
11340 return ExprError();
11341
11342 if (!getDerived().AlwaysRebuild() &&
11343 Type == E->getTypeSourceInfo() &&
11344 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011345 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011346
11347 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11348 SrcExpr.get(), Type,
11349 E->getRParenLoc());
11350}
11351
11352template<typename Derived>
11353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011354TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011355 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011356
Craig Topperc3ec1492014-05-26 06:22:03 +000011357 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011358 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11359
11360 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011361 blockScope->TheDecl->setBlockMissingReturnType(
11362 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011363
Chris Lattner01cf8db2011-07-20 06:58:45 +000011364 SmallVector<ParmVarDecl*, 4> params;
11365 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011366
John McCallc8e321d2016-03-01 02:09:25 +000011367 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11368
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011369 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011370 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011371 if (getDerived().TransformFunctionTypeParams(
11372 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11373 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11374 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011375 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011376 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011377 }
John McCall490112f2011-02-04 18:33:18 +000011378
Eli Friedman34b49062012-01-26 03:00:14 +000011379 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011380 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011381
John McCallc8e321d2016-03-01 02:09:25 +000011382 auto epi = exprFunctionType->getExtProtoInfo();
11383 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11384
Jordan Rose5c382722013-03-08 21:51:21 +000011385 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011386 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011387 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011388
11389 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011390 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011391 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011392
11393 if (!oldBlock->blockMissingReturnType()) {
11394 blockScope->HasImplicitReturnType = false;
11395 blockScope->ReturnType = exprResultType;
11396 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011397
John McCall3882ace2011-01-05 12:14:39 +000011398 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011399 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011400 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011401 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011402 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011403 }
John McCall3882ace2011-01-05 12:14:39 +000011404
John McCall490112f2011-02-04 18:33:18 +000011405#ifndef NDEBUG
11406 // In builds with assertions, make sure that we captured everything we
11407 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011408 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011409 for (const auto &I : oldBlock->captures()) {
11410 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011411
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011412 // Ignore parameter packs.
11413 if (isa<ParmVarDecl>(oldCapture) &&
11414 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11415 continue;
John McCall490112f2011-02-04 18:33:18 +000011416
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011417 VarDecl *newCapture =
11418 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11419 oldCapture));
11420 assert(blockScope->CaptureMap.count(newCapture));
11421 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011422 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011423 }
11424#endif
11425
11426 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011427 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011428}
11429
Mike Stump11289f42009-09-09 15:08:12 +000011430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011431ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011432TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011433 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011434}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011435
11436template<typename Derived>
11437ExprResult
11438TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011439 QualType RetTy = getDerived().TransformType(E->getType());
11440 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011441 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011442 SubExprs.reserve(E->getNumSubExprs());
11443 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11444 SubExprs, &ArgumentChanged))
11445 return ExprError();
11446
11447 if (!getDerived().AlwaysRebuild() &&
11448 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011449 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011450
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011451 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011452 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011453}
Chad Rosier1dcde962012-08-08 18:46:20 +000011454
Douglas Gregora16548e2009-08-11 05:31:07 +000011455//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011456// Type reconstruction
11457//===----------------------------------------------------------------------===//
11458
Mike Stump11289f42009-09-09 15:08:12 +000011459template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011460QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11461 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011462 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011463 getDerived().getBaseEntity());
11464}
11465
Mike Stump11289f42009-09-09 15:08:12 +000011466template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011467QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11468 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011469 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011470 getDerived().getBaseEntity());
11471}
11472
Mike Stump11289f42009-09-09 15:08:12 +000011473template<typename Derived>
11474QualType
John McCall70dd5f62009-10-30 00:06:24 +000011475TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11476 bool WrittenAsLValue,
11477 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011478 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011479 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011480}
11481
11482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011483QualType
John McCall70dd5f62009-10-30 00:06:24 +000011484TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11485 QualType ClassType,
11486 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011487 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11488 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011489}
11490
11491template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011492QualType TreeTransform<Derived>::RebuildObjCObjectType(
11493 QualType BaseType,
11494 SourceLocation Loc,
11495 SourceLocation TypeArgsLAngleLoc,
11496 ArrayRef<TypeSourceInfo *> TypeArgs,
11497 SourceLocation TypeArgsRAngleLoc,
11498 SourceLocation ProtocolLAngleLoc,
11499 ArrayRef<ObjCProtocolDecl *> Protocols,
11500 ArrayRef<SourceLocation> ProtocolLocs,
11501 SourceLocation ProtocolRAngleLoc) {
11502 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11503 TypeArgs, TypeArgsRAngleLoc,
11504 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11505 ProtocolRAngleLoc,
11506 /*FailOnError=*/true);
11507}
11508
11509template<typename Derived>
11510QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11511 QualType PointeeType,
11512 SourceLocation Star) {
11513 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11514}
11515
11516template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011517QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011518TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11519 ArrayType::ArraySizeModifier SizeMod,
11520 const llvm::APInt *Size,
11521 Expr *SizeExpr,
11522 unsigned IndexTypeQuals,
11523 SourceRange BracketsRange) {
11524 if (SizeExpr || !Size)
11525 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11526 IndexTypeQuals, BracketsRange,
11527 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011528
11529 QualType Types[] = {
11530 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11531 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11532 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011533 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011534 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011535 QualType SizeType;
11536 for (unsigned I = 0; I != NumTypes; ++I)
11537 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11538 SizeType = Types[I];
11539 break;
11540 }
Mike Stump11289f42009-09-09 15:08:12 +000011541
Eli Friedman9562f392012-01-25 23:20:27 +000011542 // Note that we can return a VariableArrayType here in the case where
11543 // the element type was a dependent VariableArrayType.
11544 IntegerLiteral *ArraySize
11545 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11546 /*FIXME*/BracketsRange.getBegin());
11547 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011548 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011549 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011550}
Mike Stump11289f42009-09-09 15:08:12 +000011551
Douglas Gregord6ff3322009-08-04 16:50:30 +000011552template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011553QualType
11554TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011555 ArrayType::ArraySizeModifier SizeMod,
11556 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011557 unsigned IndexTypeQuals,
11558 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011559 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011560 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011561}
11562
11563template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011564QualType
Mike Stump11289f42009-09-09 15:08:12 +000011565TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011566 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011567 unsigned IndexTypeQuals,
11568 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011569 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011570 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011571}
Mike Stump11289f42009-09-09 15:08:12 +000011572
Douglas Gregord6ff3322009-08-04 16:50:30 +000011573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011574QualType
11575TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011576 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011577 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011578 unsigned IndexTypeQuals,
11579 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011580 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011581 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011582 IndexTypeQuals, BracketsRange);
11583}
11584
11585template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011586QualType
11587TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011588 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011589 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011590 unsigned IndexTypeQuals,
11591 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011592 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011593 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011594 IndexTypeQuals, BracketsRange);
11595}
11596
11597template<typename Derived>
11598QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011599 unsigned NumElements,
11600 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011601 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011602 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011603}
Mike Stump11289f42009-09-09 15:08:12 +000011604
Douglas Gregord6ff3322009-08-04 16:50:30 +000011605template<typename Derived>
11606QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11607 unsigned NumElements,
11608 SourceLocation AttributeLoc) {
11609 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11610 NumElements, true);
11611 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011612 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11613 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011614 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011615}
Mike Stump11289f42009-09-09 15:08:12 +000011616
Douglas Gregord6ff3322009-08-04 16:50:30 +000011617template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011618QualType
11619TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011620 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011621 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011622 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011623}
Mike Stump11289f42009-09-09 15:08:12 +000011624
Douglas Gregord6ff3322009-08-04 16:50:30 +000011625template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011626QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11627 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011628 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011629 const FunctionProtoType::ExtProtoInfo &EPI) {
11630 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011631 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011632 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011633 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011634}
Mike Stump11289f42009-09-09 15:08:12 +000011635
Douglas Gregord6ff3322009-08-04 16:50:30 +000011636template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011637QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11638 return SemaRef.Context.getFunctionNoProtoType(T);
11639}
11640
11641template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011642QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11643 assert(D && "no decl found");
11644 if (D->isInvalidDecl()) return QualType();
11645
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011646 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011647 TypeDecl *Ty;
11648 if (isa<UsingDecl>(D)) {
11649 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011650 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011651 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11652
11653 // A valid resolved using typename decl points to exactly one type decl.
11654 assert(++Using->shadow_begin() == Using->shadow_end());
11655 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011656
John McCallb96ec562009-12-04 22:46:56 +000011657 } else {
11658 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11659 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11660 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11661 }
11662
11663 return SemaRef.Context.getTypeDeclType(Ty);
11664}
11665
11666template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011667QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11668 SourceLocation Loc) {
11669 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011670}
11671
11672template<typename Derived>
11673QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11674 return SemaRef.Context.getTypeOfType(Underlying);
11675}
11676
11677template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011678QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11679 SourceLocation Loc) {
11680 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011681}
11682
11683template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011684QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11685 UnaryTransformType::UTTKind UKind,
11686 SourceLocation Loc) {
11687 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11688}
11689
11690template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011691QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011692 TemplateName Template,
11693 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011694 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011695 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011696}
Mike Stump11289f42009-09-09 15:08:12 +000011697
Douglas Gregor1135c352009-08-06 05:28:30 +000011698template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011699QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11700 SourceLocation KWLoc) {
11701 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11702}
11703
11704template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011705QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11706 SourceLocation KWLoc) {
11707 return SemaRef.BuildPipeType(ValueType, KWLoc);
11708}
11709
11710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011711TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011712TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011713 bool TemplateKW,
11714 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011715 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011716 Template);
11717}
11718
11719template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011720TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011721TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11722 const IdentifierInfo &Name,
11723 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011724 QualType ObjectType,
11725 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011726 UnqualifiedId TemplateName;
11727 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011728 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011729 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011730 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011731 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011732 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011733 /*EnteringContext=*/false,
11734 Template);
John McCall31f82722010-11-12 08:19:04 +000011735 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011736}
Mike Stump11289f42009-09-09 15:08:12 +000011737
Douglas Gregora16548e2009-08-11 05:31:07 +000011738template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011739TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011740TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011741 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011742 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011743 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011744 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011745 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011746 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011747 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011748 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011749 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011750 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011751 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011752 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011753 /*EnteringContext=*/false,
11754 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011755 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011756}
Chad Rosier1dcde962012-08-08 18:46:20 +000011757
Douglas Gregor71395fa2009-11-04 00:56:37 +000011758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011759ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011760TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11761 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011762 Expr *OrigCallee,
11763 Expr *First,
11764 Expr *Second) {
11765 Expr *Callee = OrigCallee->IgnoreParenCasts();
11766 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011767
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011768 if (First->getObjectKind() == OK_ObjCProperty) {
11769 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11770 if (BinaryOperator::isAssignmentOp(Opc))
11771 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11772 First, Second);
11773 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11774 if (Result.isInvalid())
11775 return ExprError();
11776 First = Result.get();
11777 }
11778
11779 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11780 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11781 if (Result.isInvalid())
11782 return ExprError();
11783 Second = Result.get();
11784 }
11785
Douglas Gregora16548e2009-08-11 05:31:07 +000011786 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011787 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011788 if (!First->getType()->isOverloadableType() &&
11789 !Second->getType()->isOverloadableType())
11790 return getSema().CreateBuiltinArraySubscriptExpr(First,
11791 Callee->getLocStart(),
11792 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011793 } else if (Op == OO_Arrow) {
11794 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011795 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11796 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011797 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011798 // The argument is not of overloadable type, so try to create a
11799 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011800 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011801 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011802
John McCallb268a282010-08-23 23:25:46 +000011803 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011804 }
11805 } else {
John McCallb268a282010-08-23 23:25:46 +000011806 if (!First->getType()->isOverloadableType() &&
11807 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011808 // Neither of the arguments is an overloadable type, so try to
11809 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011810 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011811 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011812 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011813 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011814 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011815
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011816 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011817 }
11818 }
Mike Stump11289f42009-09-09 15:08:12 +000011819
11820 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011821 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011822 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011823
John McCallb268a282010-08-23 23:25:46 +000011824 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011825 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011826 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011827 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011828 // If we've resolved this to a particular non-member function, just call
11829 // that function. If we resolved it to a member function,
11830 // CreateOverloaded* will find that function for us.
11831 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11832 if (!isa<CXXMethodDecl>(ND))
11833 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011834 }
Mike Stump11289f42009-09-09 15:08:12 +000011835
Douglas Gregora16548e2009-08-11 05:31:07 +000011836 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011837 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011838 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011839
Douglas Gregora16548e2009-08-11 05:31:07 +000011840 // Create the overloaded operator invocation for unary operators.
11841 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011842 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011843 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011844 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011845 }
Mike Stump11289f42009-09-09 15:08:12 +000011846
Douglas Gregore9d62932011-07-15 16:25:15 +000011847 if (Op == OO_Subscript) {
11848 SourceLocation LBrace;
11849 SourceLocation RBrace;
11850
11851 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011852 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011853 LBrace = SourceLocation::getFromRawEncoding(
11854 NameLoc.CXXOperatorName.BeginOpNameLoc);
11855 RBrace = SourceLocation::getFromRawEncoding(
11856 NameLoc.CXXOperatorName.EndOpNameLoc);
11857 } else {
11858 LBrace = Callee->getLocStart();
11859 RBrace = OpLoc;
11860 }
11861
11862 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11863 First, Second);
11864 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011865
Douglas Gregora16548e2009-08-11 05:31:07 +000011866 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011867 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011868 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011869 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11870 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011872
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011873 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011874}
Mike Stump11289f42009-09-09 15:08:12 +000011875
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011876template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011877ExprResult
John McCallb268a282010-08-23 23:25:46 +000011878TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011879 SourceLocation OperatorLoc,
11880 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011881 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011882 TypeSourceInfo *ScopeType,
11883 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011884 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011885 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011886 QualType BaseType = Base->getType();
11887 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011888 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011889 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011890 !BaseType->getAs<PointerType>()->getPointeeType()
11891 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011892 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011893 return SemaRef.BuildPseudoDestructorExpr(
11894 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11895 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011896 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011897
Douglas Gregor678f90d2010-02-25 01:56:36 +000011898 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011899 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11900 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11901 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11902 NameInfo.setNamedTypeInfo(DestroyedType);
11903
Richard Smith8e4a3862012-05-15 06:15:11 +000011904 // The scope type is now known to be a valid nested name specifier
11905 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011906 if (ScopeType) {
11907 if (!ScopeType->getType()->getAs<TagType>()) {
11908 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11909 diag::err_expected_class_or_namespace)
11910 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11911 return ExprError();
11912 }
11913 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11914 CCLoc);
11915 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011916
Abramo Bagnara7945c982012-01-27 09:46:47 +000011917 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011918 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011919 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011920 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011921 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011922 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011923 /*TemplateArgs*/ nullptr,
11924 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011925}
11926
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011927template<typename Derived>
11928StmtResult
11929TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011930 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011931 CapturedDecl *CD = S->getCapturedDecl();
11932 unsigned NumParams = CD->getNumParams();
11933 unsigned ContextParamPos = CD->getContextParamPosition();
11934 SmallVector<Sema::CapturedParamNameType, 4> Params;
11935 for (unsigned I = 0; I < NumParams; ++I) {
11936 if (I != ContextParamPos) {
11937 Params.push_back(
11938 std::make_pair(
11939 CD->getParam(I)->getName(),
11940 getDerived().TransformType(CD->getParam(I)->getType())));
11941 } else {
11942 Params.push_back(std::make_pair(StringRef(), QualType()));
11943 }
11944 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011945 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011946 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011947 StmtResult Body;
11948 {
11949 Sema::CompoundScopeRAII CompoundScope(getSema());
11950 Body = getDerived().TransformStmt(S->getCapturedStmt());
11951 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011952
11953 if (Body.isInvalid()) {
11954 getSema().ActOnCapturedRegionError();
11955 return StmtError();
11956 }
11957
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011958 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011959}
11960
Douglas Gregord6ff3322009-08-04 16:50:30 +000011961} // end namespace clang
11962
Hans Wennborg59dbe862015-09-29 20:56:43 +000011963#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H