blob: 825a2008d4e8285918f4b4ef28bbad9a7f8f899e [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000702 /// \brief Build an Objective-C object type.
703 ///
704 /// By default, performs semantic analysis when building the object type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildObjCObjectType(QualType BaseType,
707 SourceLocation Loc,
708 SourceLocation TypeArgsLAngleLoc,
709 ArrayRef<TypeSourceInfo *> TypeArgs,
710 SourceLocation TypeArgsRAngleLoc,
711 SourceLocation ProtocolLAngleLoc,
712 ArrayRef<ObjCProtocolDecl *> Protocols,
713 ArrayRef<SourceLocation> ProtocolLocs,
714 SourceLocation ProtocolRAngleLoc);
715
716 /// \brief Build a new Objective-C object pointer type given the pointee type.
717 ///
718 /// By default, directly builds the pointer type, with no additional semantic
719 /// analysis.
720 QualType RebuildObjCObjectPointerType(QualType PointeeType,
721 SourceLocation Star);
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new array type given the element type, size
724 /// modifier, size of the array (if known), size expression, and index type
725 /// qualifiers.
726 ///
727 /// By default, performs semantic analysis when building the array type.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 QualType RebuildArrayType(QualType ElementType,
731 ArrayType::ArraySizeModifier SizeMod,
732 const llvm::APInt *Size,
733 Expr *SizeExpr,
734 unsigned IndexTypeQuals,
735 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737 /// \brief Build a new constant array type given the element type, size
738 /// modifier, (known) size of the array, and index type qualifiers.
739 ///
740 /// By default, performs semantic analysis when building the array type.
741 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000742 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 ArrayType::ArraySizeModifier SizeMod,
744 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000745 unsigned IndexTypeQuals,
746 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new incomplete array type given the element type, size
749 /// modifier, and index type qualifiers.
750 ///
751 /// By default, performs semantic analysis when building the array type.
752 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000753 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757
Mike Stump11289f42009-09-09 15:08:12 +0000758 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 /// size modifier, size expression, and index type qualifiers.
760 ///
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000763 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000765 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 unsigned IndexTypeQuals,
767 SourceRange BracketsRange);
768
Mike Stump11289f42009-09-09 15:08:12 +0000769 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// size modifier, size expression, and index type qualifiers.
771 ///
772 /// By default, performs semantic analysis when building the array type.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000774 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000776 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 unsigned IndexTypeQuals,
778 SourceRange BracketsRange);
779
780 /// \brief Build a new vector type given the element type and
781 /// number of elements.
782 ///
783 /// By default, performs semantic analysis when building the vector type.
784 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000785 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000786 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000787
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// \brief Build a new extended vector type given the element type and
789 /// number of elements.
790 ///
791 /// By default, performs semantic analysis when building the vector type.
792 /// Subclasses may override this routine to provide different behavior.
793 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
796 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 /// given the element type and number of elements.
798 ///
799 /// By default, performs semantic analysis when building the vector type.
800 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000801 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000802 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new function type.
806 ///
807 /// By default, performs semantic analysis when building the function type.
808 /// Subclasses may override this routine to provide different behavior.
809 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000810 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000811 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000812
John McCall550e0c22009-10-21 00:40:46 +0000813 /// \brief Build a new unprototyped function type.
814 QualType RebuildFunctionNoProtoType(QualType ResultType);
815
John McCallb96ec562009-12-04 22:46:56 +0000816 /// \brief Rebuild an unresolved typename type, given the decl that
817 /// the UnresolvedUsingTypenameDecl was transformed to.
818 QualType RebuildUnresolvedUsingType(Decl *D);
819
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000821 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 return SemaRef.Context.getTypeDeclType(Typedef);
823 }
824
825 /// \brief Build a new class/struct/union type.
826 QualType RebuildRecordType(RecordDecl *Record) {
827 return SemaRef.Context.getTypeDeclType(Record);
828 }
829
830 /// \brief Build a new Enum type.
831 QualType RebuildEnumType(EnumDecl *Enum) {
832 return SemaRef.Context.getTypeDeclType(Enum);
833 }
John McCallfcc33b02009-09-05 00:15:47 +0000834
Mike Stump11289f42009-09-09 15:08:12 +0000835 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 ///
837 /// By default, performs semantic analysis when building the typeof type.
838 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000839 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, builds a new TypeOfType with the given underlying type.
844 QualType RebuildTypeOfType(QualType Underlying);
845
Alexis Hunte852b102011-05-24 22:41:36 +0000846 /// \brief Build a new unary transform type.
847 QualType RebuildUnaryTransformType(QualType BaseType,
848 UnaryTransformType::UTTKind UKind,
849 SourceLocation Loc);
850
Richard Smith74aeef52013-04-26 16:15:35 +0000851 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 ///
853 /// By default, performs semantic analysis when building the decltype type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000855 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000858 ///
859 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000860 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000861 // Note, IsDependent is always false here: we implicitly convert an 'auto'
862 // which has been deduced to a dependent type into an undeduced 'auto', so
863 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000864 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000865 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000866 }
867
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868 /// \brief Build a new template specialization type.
869 ///
870 /// By default, performs semantic analysis when building the template
871 /// specialization type. Subclasses may override this routine to provide
872 /// different behavior.
873 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000874 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000875 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000876
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000877 /// \brief Build a new parenthesized type.
878 ///
879 /// By default, builds a new ParenType type from the inner type.
880 /// Subclasses may override this routine to provide different behavior.
881 QualType RebuildParenType(QualType InnerType) {
882 return SemaRef.Context.getParenType(InnerType);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new qualified name type.
886 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000887 /// By default, builds a new ElaboratedType type from the keyword,
888 /// the nested-name-specifier and the named type.
889 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000890 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
891 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getElaboratedType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000896 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000897 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000898
899 /// \brief Build a new typename type that refers to a template-id.
900 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000901 /// By default, builds a new DependentNameType type from the
902 /// nested-name-specifier and the given type. Subclasses may override
903 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000904 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 ElaboratedTypeKeyword Keyword,
906 NestedNameSpecifierLoc QualifierLoc,
907 const IdentifierInfo *Name,
908 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000909 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000910 // Rebuild the template name.
911 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000912 CXXScopeSpec SS;
913 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000915 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
916 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000917
Douglas Gregora7a795b2011-03-01 20:11:18 +0000918 if (InstName.isNull())
919 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000920
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 // If it's still dependent, make a dependent specialization.
922 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
Douglas Gregora7a795b2011-03-01 20:11:18 +0000928 // Otherwise, make an elaborated type wrapping a non-dependent
929 // specialization.
930 QualType T =
931 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
932 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Craig Topperc3ec1492014-05-26 06:22:03 +0000934 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000935 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000939 T);
940 }
941
Douglas Gregord6ff3322009-08-04 16:50:30 +0000942 /// \brief Build a new typename type that refers to an identifier.
943 ///
944 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000946 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000947 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000948 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000949 NestedNameSpecifierLoc QualifierLoc,
950 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000953 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 // If the name is still dependent, just build a new dependent name type.
957 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000958 return SemaRef.Context.getDependentNameType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000960 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 }
962
Abramo Bagnara6150c882010-05-11 21:36:43 +0000963 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000964 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000965 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000966
967 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
968
Abramo Bagnarad7548482010-05-19 21:37:53 +0000969 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000970 // into a non-dependent elaborated-type-specifier. Find the tag we're
971 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000972 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000973 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
974 if (!DC)
975 return QualType();
976
John McCallbf8c5192010-05-27 06:40:31 +0000977 if (SemaRef.RequireCompleteDeclContext(SS, DC))
978 return QualType();
979
Craig Topperc3ec1492014-05-26 06:22:03 +0000980 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000981 SemaRef.LookupQualifiedName(Result, DC);
982 switch (Result.getResultKind()) {
983 case LookupResult::NotFound:
984 case LookupResult::NotFoundInCurrentInstantiation:
985 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000986
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 case LookupResult::Found:
988 Tag = Result.getAsSingle<TagDecl>();
989 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000990
Douglas Gregore677daf2010-03-31 22:19:08 +0000991 case LookupResult::FoundOverloaded:
992 case LookupResult::FoundUnresolvedValue:
993 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000994
Douglas Gregore677daf2010-03-31 22:19:08 +0000995 case LookupResult::Ambiguous:
996 // Let the LookupResult structure handle ambiguities.
997 return QualType();
998 }
999
1000 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 // Check where the name exists but isn't a tag type and use that to emit
1002 // better diagnostics.
1003 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1004 SemaRef.LookupQualifiedName(Result, DC);
1005 switch (Result.getResultKind()) {
1006 case LookupResult::Found:
1007 case LookupResult::FoundOverloaded:
1008 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001009 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 unsigned Kind = 0;
1011 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001012 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1013 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001014 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1015 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1016 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001017 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001018 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001019 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001020 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001021 break;
1022 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001023 return QualType();
1024 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001025
Richard Trieucaa33d32011-06-10 03:11:26 +00001026 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001027 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001028 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1030 return QualType();
1031 }
1032
1033 // Build the elaborated-type-specifier type.
1034 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 return SemaRef.Context.getElaboratedType(Keyword,
1036 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001037 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregor822d0302011-01-12 17:07:58 +00001040 /// \brief Build a new pack expansion type.
1041 ///
1042 /// By default, builds a new PackExpansionType type from the given pattern.
1043 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001044 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001045 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001046 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001047 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001048 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1049 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001050 }
1051
Eli Friedman0dfb8892011-10-06 23:00:33 +00001052 /// \brief Build a new atomic type given its value type.
1053 ///
1054 /// By default, performs semantic analysis when building the atomic type.
1055 /// Subclasses may override this routine to provide different behavior.
1056 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1057
Xiuli Pan9c14e282016-01-09 12:53:17 +00001058 /// \brief Build a new pipe type given its value type.
1059 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1060
Douglas Gregor71dc5092009-08-06 06:41:21 +00001061 /// \brief Build a new template name given a nested name specifier, a flag
1062 /// indicating whether the "template" keyword was provided, and the template
1063 /// that the template name refers to.
1064 ///
1065 /// By default, builds the new template name directly. Subclasses may override
1066 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001067 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001068 bool TemplateKW,
1069 TemplateDecl *Template);
1070
Douglas Gregor71dc5092009-08-06 06:41:21 +00001071 /// \brief Build a new template name given a nested name specifier and the
1072 /// name that is referred to as a template.
1073 ///
1074 /// By default, performs semantic analysis to determine whether the name can
1075 /// be resolved to a specific template, then builds the appropriate kind of
1076 /// template name. Subclasses may override this routine to provide different
1077 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001078 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1079 const IdentifierInfo &Name,
1080 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001081 QualType ObjectType,
1082 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregor71395fa2009-11-04 00:56:37 +00001084 /// \brief Build a new template name given a nested name specifier and the
1085 /// overloaded operator name that is referred to as a template.
1086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001091 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001092 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001093 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001094 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001095
1096 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001097 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001098 ///
1099 /// By default, performs semantic analysis to determine whether the name can
1100 /// be resolved to a specific template, then builds the appropriate kind of
1101 /// template name. Subclasses may override this routine to provide different
1102 /// behavior.
1103 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1104 const TemplateArgument &ArgPack) {
1105 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1106 }
1107
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 /// \brief Build a new compound statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 MultiStmtArg Statements,
1114 SourceLocation RBraceLoc,
1115 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001116 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 IsStmtExpr);
1118 }
1119
1120 /// \brief Build a new case statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001124 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001125 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001127 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001129 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 ColonLoc);
1131 }
Mike Stump11289f42009-09-09 15:08:12 +00001132
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 /// \brief Attach the body to a new case statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001137 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 getSema().ActOnCaseStmtBody(S, Body);
1139 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Build a new default statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Stmt *SubStmt) {
1149 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001150 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 }
Mike Stump11289f42009-09-09 15:08:12 +00001152
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 /// \brief Build a new label statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001157 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1158 SourceLocation ColonLoc, Stmt *SubStmt) {
1159 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Richard Smithc202b282012-04-14 00:33:13 +00001162 /// \brief Build a new label statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001166 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1167 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001168 Stmt *SubStmt) {
1169 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1170 }
1171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new "if" statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001176 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1177 Sema::ConditionResult Cond, Stmt *Then,
1178 SourceLocation ElseLoc, Stmt *Else) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, nullptr, Cond, Then,
1180 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 /// \brief Start building a new switch statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001188 Sema::ConditionResult Cond) {
Richard Smithc7a05a92016-06-29 21:17:59 +00001189 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, nullptr, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Attach the body to the switch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001197 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
1200
1201 /// \brief Build a new while statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001205 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1206 Sema::ConditionResult Cond, Stmt *Body) {
1207 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 /// \brief Build a new do-while statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 SourceLocation WhileLoc, SourceLocation LParenLoc,
1216 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001217 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1218 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
1220
1221 /// \brief Build a new for statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001226 Stmt *Init, Sema::ConditionResult Cond,
1227 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1228 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001229 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001230 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 /// \brief Build a new goto statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001237 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1238 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001239 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
1241
1242 /// \brief Build a new indirect goto statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001247 SourceLocation StarLoc,
1248 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001249 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 /// \brief Build a new return statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001256 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001257 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregorebe10102009-08-20 07:17:43 +00001260 /// \brief Build a new declaration statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001264 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001265 SourceLocation StartLoc, SourceLocation EndLoc) {
1266 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001267 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Anders Carlssonaaeef072010-01-24 05:50:09 +00001270 /// \brief Build a new inline asm statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001274 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1275 bool IsVolatile, unsigned NumOutputs,
1276 unsigned NumInputs, IdentifierInfo **Names,
1277 MultiExprArg Constraints, MultiExprArg Exprs,
1278 Expr *AsmString, MultiExprArg Clobbers,
1279 SourceLocation RParenLoc) {
1280 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1281 NumInputs, Names, Constraints, Exprs,
1282 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001283 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284
Chad Rosier32503022012-06-11 20:47:18 +00001285 /// \brief Build a new MS style inline asm statement.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001289 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001290 ArrayRef<Token> AsmToks,
1291 StringRef AsmString,
1292 unsigned NumOutputs, unsigned NumInputs,
1293 ArrayRef<StringRef> Constraints,
1294 ArrayRef<StringRef> Clobbers,
1295 ArrayRef<Expr*> Exprs,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1298 NumOutputs, NumInputs,
1299 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001300 }
1301
Richard Smith9f690bd2015-10-27 06:02:45 +00001302 /// \brief Build a new co_return statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1307 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1308 }
1309
1310 /// \brief Build a new co_await expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1315 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1316 }
1317
1318 /// \brief Build a new co_yield expression.
1319 ///
1320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
1322 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1323 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1324 }
1325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001332 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001333 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001334 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001335 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001336 }
1337
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001338 /// \brief Rebuild an Objective-C exception declaration.
1339 ///
1340 /// By default, performs semantic analysis to build the new declaration.
1341 /// Subclasses may override this routine to provide different behavior.
1342 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1343 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001344 return getSema().BuildObjCExceptionDecl(TInfo, T,
1345 ExceptionDecl->getInnerLocStart(),
1346 ExceptionDecl->getLocation(),
1347 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001355 SourceLocation RParenLoc,
1356 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001357 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001358 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001359 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001361
James Dennett2a4d13c2012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001366 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001367 Stmt *Body) {
1368 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001370
James Dennett2a4d13c2012-06-15 07:13:21 +00001371 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001375 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *Operand) {
1377 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001379
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001380 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001381 ///
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001384 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001385 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001386 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001387 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001388 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001389 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001390 return getSema().ActOnOpenMPExecutableDirective(
1391 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001392 }
1393
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001394 /// \brief Build a new OpenMP 'if' clause.
1395 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001396 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001397 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001398 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1399 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001400 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001401 SourceLocation NameModifierLoc,
1402 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001403 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001404 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1405 LParenLoc, NameModifierLoc, ColonLoc,
1406 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001407 }
1408
Alexey Bataev3778b602014-07-17 07:32:53 +00001409 /// \brief Build a new OpenMP 'final' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new OpenMP clause.
1412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1417 EndLoc);
1418 }
1419
Alexey Bataev568a8332014-03-06 06:15:19 +00001420 /// \brief Build a new OpenMP 'num_threads' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1425 SourceLocation StartLoc,
1426 SourceLocation LParenLoc,
1427 SourceLocation EndLoc) {
1428 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1429 LParenLoc, EndLoc);
1430 }
1431
Alexey Bataev62c87d22014-03-21 04:51:18 +00001432 /// \brief Build a new OpenMP 'safelen' clause.
1433 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001434 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001435 /// Subclasses may override this routine to provide different behavior.
1436 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1440 }
1441
Alexey Bataev66b15b52015-08-21 11:14:16 +00001442 /// \brief Build a new OpenMP 'simdlen' clause.
1443 ///
1444 /// By default, performs semantic analysis to build the new OpenMP clause.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1450 }
1451
Alexander Musman8bd31e62014-05-27 15:12:19 +00001452 /// \brief Build a new OpenMP 'collapse' clause.
1453 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001454 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1457 SourceLocation LParenLoc,
1458 SourceLocation EndLoc) {
1459 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1460 EndLoc);
1461 }
1462
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001463 /// \brief Build a new OpenMP 'default' clause.
1464 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001465 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001466 /// Subclasses may override this routine to provide different behavior.
1467 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1468 SourceLocation KindKwLoc,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1473 StartLoc, LParenLoc, EndLoc);
1474 }
1475
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001476 /// \brief Build a new OpenMP 'proc_bind' clause.
1477 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001478 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1481 SourceLocation KindKwLoc,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation EndLoc) {
1485 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1486 StartLoc, LParenLoc, EndLoc);
1487 }
1488
Alexey Bataev56dafe82014-06-20 07:16:17 +00001489 /// \brief Build a new OpenMP 'schedule' clause.
1490 ///
1491 /// By default, performs semantic analysis to build the new OpenMP clause.
1492 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001493 OMPClause *RebuildOMPScheduleClause(
1494 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1495 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1496 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1497 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001498 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001499 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1500 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001501 }
1502
Alexey Bataev10e775f2015-07-30 11:36:16 +00001503 /// \brief Build a new OpenMP 'ordered' clause.
1504 ///
1505 /// By default, performs semantic analysis to build the new OpenMP clause.
1506 /// Subclasses may override this routine to provide different behavior.
1507 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1508 SourceLocation EndLoc,
1509 SourceLocation LParenLoc, Expr *Num) {
1510 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1511 }
1512
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001513 /// \brief Build a new OpenMP 'private' clause.
1514 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001515 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001516 /// Subclasses may override this routine to provide different behavior.
1517 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1518 SourceLocation StartLoc,
1519 SourceLocation LParenLoc,
1520 SourceLocation EndLoc) {
1521 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1522 EndLoc);
1523 }
1524
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001525 /// \brief Build a new OpenMP 'firstprivate' clause.
1526 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001527 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001528 /// Subclasses may override this routine to provide different behavior.
1529 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1530 SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1534 EndLoc);
1535 }
1536
Alexander Musman1bb328c2014-06-04 13:06:39 +00001537 /// \brief Build a new OpenMP 'lastprivate' clause.
1538 ///
1539 /// By default, performs semantic analysis to build the new OpenMP clause.
1540 /// Subclasses may override this routine to provide different behavior.
1541 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1546 EndLoc);
1547 }
1548
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001549 /// \brief Build a new OpenMP 'shared' clause.
1550 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001551 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001552 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001553 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1554 SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1558 EndLoc);
1559 }
1560
Alexey Bataevc5e02582014-06-16 07:08:35 +00001561 /// \brief Build a new OpenMP 'reduction' clause.
1562 ///
1563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1566 SourceLocation StartLoc,
1567 SourceLocation LParenLoc,
1568 SourceLocation ColonLoc,
1569 SourceLocation EndLoc,
1570 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001571 const DeclarationNameInfo &ReductionId,
1572 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001573 return getSema().ActOnOpenMPReductionClause(
1574 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001575 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001576 }
1577
Alexander Musman8dba6642014-04-22 13:09:42 +00001578 /// \brief Build a new OpenMP 'linear' clause.
1579 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001580 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001581 /// Subclasses may override this routine to provide different behavior.
1582 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1583 SourceLocation StartLoc,
1584 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001585 OpenMPLinearClauseKind Modifier,
1586 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001587 SourceLocation ColonLoc,
1588 SourceLocation EndLoc) {
1589 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001590 Modifier, ModifierLoc, ColonLoc,
1591 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001592 }
1593
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001594 /// \brief Build a new OpenMP 'aligned' clause.
1595 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001596 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001597 /// Subclasses may override this routine to provide different behavior.
1598 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation ColonLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1604 LParenLoc, ColonLoc, EndLoc);
1605 }
1606
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001607 /// \brief Build a new OpenMP 'copyin' clause.
1608 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001609 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataevbae9a792014-06-27 10:37:06 +00001619 /// \brief Build a new OpenMP 'copyprivate' clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev6125da92014-07-21 11:26:11 +00001631 /// \brief Build a new OpenMP 'flush' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1636 SourceLocation StartLoc,
1637 SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1640 EndLoc);
1641 }
1642
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001643 /// \brief Build a new OpenMP 'depend' pseudo clause.
1644 ///
1645 /// By default, performs semantic analysis to build the new OpenMP clause.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *
1648 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1649 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc, SourceLocation LParenLoc,
1651 SourceLocation EndLoc) {
1652 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1653 StartLoc, LParenLoc, EndLoc);
1654 }
1655
Michael Wonge710d542015-08-07 16:16:36 +00001656 /// \brief Build a new OpenMP 'device' clause.
1657 ///
1658 /// By default, performs semantic analysis to build the new statement.
1659 /// Subclasses may override this routine to provide different behavior.
1660 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1661 SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001663 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001664 EndLoc);
1665 }
1666
Kelvin Li0bff7af2015-11-23 05:32:03 +00001667 /// \brief Build a new OpenMP 'map' clause.
1668 ///
1669 /// By default, performs semantic analysis to build the new OpenMP clause.
1670 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001671 OMPClause *
1672 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1673 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1674 SourceLocation MapLoc, SourceLocation ColonLoc,
1675 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1676 SourceLocation LParenLoc, SourceLocation EndLoc) {
1677 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1678 IsMapTypeImplicit, MapLoc, ColonLoc,
1679 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001680 }
1681
Kelvin Li099bb8c2015-11-24 20:50:12 +00001682 /// \brief Build a new OpenMP 'num_teams' clause.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
1686 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation EndLoc) {
1689 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1690 EndLoc);
1691 }
1692
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001693 /// \brief Build a new OpenMP 'thread_limit' clause.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1698 SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation EndLoc) {
1701 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1702 LParenLoc, EndLoc);
1703 }
1704
Alexey Bataeva0569352015-12-01 10:17:31 +00001705 /// \brief Build a new OpenMP 'priority' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new statement.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1713 EndLoc);
1714 }
1715
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001716 /// \brief Build a new OpenMP 'grainsize' clause.
1717 ///
1718 /// By default, performs semantic analysis to build the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
1720 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
1722 SourceLocation EndLoc) {
1723 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1724 EndLoc);
1725 }
1726
Alexey Bataev382967a2015-12-08 12:06:20 +00001727 /// \brief Build a new OpenMP 'num_tasks' clause.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
1731 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataev28c75412015-12-15 08:19:24 +00001738 /// \brief Build a new OpenMP 'hint' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new statement.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1746 }
1747
Carlo Bertollib4adf552016-01-15 18:50:31 +00001748 /// \brief Build a new OpenMP 'dist_schedule' clause.
1749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *
1753 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1754 Expr *ChunkSize, SourceLocation StartLoc,
1755 SourceLocation LParenLoc, SourceLocation KindLoc,
1756 SourceLocation CommaLoc, SourceLocation EndLoc) {
1757 return getSema().ActOnOpenMPDistScheduleClause(
1758 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1759 }
1760
Samuel Antao661c0902016-05-26 17:39:58 +00001761 /// \brief Build a new OpenMP 'to' clause.
1762 ///
1763 /// By default, performs semantic analysis to build the new statement.
1764 /// Subclasses may override this routine to provide different behavior.
1765 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1770 }
1771
Samuel Antaoec172c62016-05-26 17:49:04 +00001772 /// \brief Build a new OpenMP 'from' clause.
1773 ///
1774 /// By default, performs semantic analysis to build the new statement.
1775 /// Subclasses may override this routine to provide different behavior.
1776 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1777 SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1781 EndLoc);
1782 }
1783
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) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006269 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006270 Sema::ConditionResult Cond = getDerived().TransformCondition(
6271 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006272 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6273 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006274 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006275 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006276
Richard Smithb130fe72016-06-23 19:16:49 +00006277 // If this is a constexpr if, determine which arm we should instantiate.
6278 llvm::Optional<bool> ConstexprConditionValue;
6279 if (S->isConstexpr())
6280 ConstexprConditionValue = Cond.getKnownValue();
6281
Douglas Gregorebe10102009-08-20 07:17:43 +00006282 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006283 StmtResult Then;
6284 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6285 Then = getDerived().TransformStmt(S->getThen());
6286 if (Then.isInvalid())
6287 return StmtError();
6288 } else {
6289 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6290 }
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006293 StmtResult Else;
6294 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6295 Else = getDerived().TransformStmt(S->getElse());
6296 if (Else.isInvalid())
6297 return StmtError();
6298 }
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregorebe10102009-08-20 07:17:43 +00006300 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006301 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006302 Then.get() == S->getThen() &&
6303 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006304 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006305
Richard Smithb130fe72016-06-23 19:16:49 +00006306 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6307 Then.get(), S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006308}
6309
6310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006311StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006312TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006313 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006314 Sema::ConditionResult Cond = getDerived().TransformCondition(
6315 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6316 Sema::ConditionKind::Switch);
6317 if (Cond.isInvalid())
6318 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006319
Douglas Gregorebe10102009-08-20 07:17:43 +00006320 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006321 StmtResult Switch
Richard Smith03a4aa32016-06-23 19:02:52 +00006322 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006323 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006324 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregorebe10102009-08-20 07:17:43 +00006326 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006327 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006328 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006330
Douglas Gregorebe10102009-08-20 07:17:43 +00006331 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006332 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6333 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006334}
Mike Stump11289f42009-09-09 15:08:12 +00006335
Douglas Gregorebe10102009-08-20 07:17:43 +00006336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006337StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006338TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006339 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006340 Sema::ConditionResult Cond = getDerived().TransformCondition(
6341 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6342 Sema::ConditionKind::Boolean);
6343 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006345
Douglas Gregorebe10102009-08-20 07:17:43 +00006346 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006347 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006349 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregorebe10102009-08-20 07:17:43 +00006351 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006352 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006354 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006355
Richard Smith03a4aa32016-06-23 19:02:52 +00006356 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006357}
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregorebe10102009-08-20 07:17:43 +00006359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006360StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006361TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006362 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006363 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006364 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006367 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006368 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006369 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 if (!getDerived().AlwaysRebuild() &&
6373 Cond.get() == S->getCond() &&
6374 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006375 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006376
John McCallb268a282010-08-23 23:25:46 +00006377 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6378 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006379 S->getRParenLoc());
6380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregorebe10102009-08-20 07:17:43 +00006382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006383StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006384TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006385 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006386 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006387 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006388 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006389
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006390 // In OpenMP loop region loop control variable must be captured and be
6391 // private. Perform analysis of first part (if any).
6392 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6393 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6394
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006396 Sema::ConditionResult Cond = getDerived().TransformCondition(
6397 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6398 Sema::ConditionKind::Boolean);
6399 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006401
Douglas Gregorebe10102009-08-20 07:17:43 +00006402 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006403 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006406
Richard Smith945f8d32013-01-14 22:39:08 +00006407 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006408 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006409 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006410
Douglas Gregorebe10102009-08-20 07:17:43 +00006411 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006412 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006414 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregorebe10102009-08-20 07:17:43 +00006416 if (!getDerived().AlwaysRebuild() &&
6417 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006418 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006419 Inc.get() == S->getInc() &&
6420 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006421 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregorebe10102009-08-20 07:17:43 +00006423 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006424 Init.get(), Cond, FullInc,
6425 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006426}
6427
6428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006429StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006430TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006431 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6432 S->getLabel());
6433 if (!LD)
6434 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006435
Douglas Gregorebe10102009-08-20 07:17:43 +00006436 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006437 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006438 cast<LabelDecl>(LD));
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>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006444 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006445 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006446 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006447 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregorebe10102009-08-20 07:17:43 +00006449 if (!getDerived().AlwaysRebuild() &&
6450 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006451 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006452
6453 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006454 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006455}
6456
6457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006458StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006459TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006460 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006461}
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregorebe10102009-08-20 07:17:43 +00006463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006464StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006465TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006466 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregorebe10102009-08-20 07:17:43 +00006469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006471TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006472 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6473 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006474 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006476
Mike Stump11289f42009-09-09 15:08:12 +00006477 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006478 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006479 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006485 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006486 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006487 for (auto *D : S->decls()) {
6488 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006489 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006490 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006491
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006492 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006493 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006494
Douglas Gregorebe10102009-08-20 07:17:43 +00006495 Decls.push_back(Transformed);
6496 }
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregorebe10102009-08-20 07:17:43 +00006498 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006499 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006500
Rafael Espindolaab417692013-07-09 12:05:01 +00006501 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregorebe10102009-08-20 07:17:43 +00006504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006505StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006506TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006507
Benjamin Kramerf0623432012-08-23 22:51:59 +00006508 SmallVector<Expr*, 8> Constraints;
6509 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006510 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006511
John McCalldadc5752010-08-24 06:29:42 +00006512 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006513 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006514
6515 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006516
Anders Carlssonaaeef072010-01-24 05:50:09 +00006517 // Go through the outputs.
6518 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006519 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006520
Anders Carlssonaaeef072010-01-24 05:50:09 +00006521 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006522 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006523
Anders Carlssonaaeef072010-01-24 05:50:09 +00006524 // Transform the output expr.
6525 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006526 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006527 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006528 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006529
Anders Carlssonaaeef072010-01-24 05:50:09 +00006530 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006531
John McCallb268a282010-08-23 23:25:46 +00006532 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006534
Anders Carlssonaaeef072010-01-24 05:50:09 +00006535 // Go through the inputs.
6536 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006537 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006538
Anders Carlssonaaeef072010-01-24 05:50:09 +00006539 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006540 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006541
Anders Carlssonaaeef072010-01-24 05:50:09 +00006542 // Transform the input expr.
6543 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006544 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006545 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006546 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006547
Anders Carlssonaaeef072010-01-24 05:50:09 +00006548 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006549
John McCallb268a282010-08-23 23:25:46 +00006550 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Anders Carlssonaaeef072010-01-24 05:50:09 +00006553 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006554 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006555
6556 // Go through the clobbers.
6557 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006558 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006559
6560 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006561 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006562 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6563 S->isVolatile(), S->getNumOutputs(),
6564 S->getNumInputs(), Names.data(),
6565 Constraints, Exprs, AsmString.get(),
6566 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006567}
6568
Chad Rosier32503022012-06-11 20:47:18 +00006569template<typename Derived>
6570StmtResult
6571TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006572 ArrayRef<Token> AsmToks =
6573 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006574
John McCallf413f5e2013-05-03 00:10:13 +00006575 bool HadError = false, HadChange = false;
6576
6577 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6578 SmallVector<Expr*, 8> TransformedExprs;
6579 TransformedExprs.reserve(SrcExprs.size());
6580 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6581 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6582 if (!Result.isUsable()) {
6583 HadError = true;
6584 } else {
6585 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006586 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006587 }
6588 }
6589
6590 if (HadError) return StmtError();
6591 if (!HadChange && !getDerived().AlwaysRebuild())
6592 return Owned(S);
6593
Chad Rosierb6f46c12012-08-15 16:53:30 +00006594 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006595 AsmToks, S->getAsmString(),
6596 S->getNumOutputs(), S->getNumInputs(),
6597 S->getAllConstraints(), S->getClobbers(),
6598 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006599}
Douglas Gregorebe10102009-08-20 07:17:43 +00006600
Richard Smith9f690bd2015-10-27 06:02:45 +00006601// C++ Coroutines TS
6602
6603template<typename Derived>
6604StmtResult
6605TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6606 // The coroutine body should be re-formed by the caller if necessary.
6607 return getDerived().TransformStmt(S->getBody());
6608}
6609
6610template<typename Derived>
6611StmtResult
6612TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6613 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6614 /*NotCopyInit*/false);
6615 if (Result.isInvalid())
6616 return StmtError();
6617
6618 // Always rebuild; we don't know if this needs to be injected into a new
6619 // context or if the promise type has changed.
6620 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6621}
6622
6623template<typename Derived>
6624ExprResult
6625TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6626 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6627 /*NotCopyInit*/false);
6628 if (Result.isInvalid())
6629 return ExprError();
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().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6634}
6635
6636template<typename Derived>
6637ExprResult
6638TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *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().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6647}
6648
6649// Objective-C Statements.
6650
Douglas Gregorebe10102009-08-20 07:17:43 +00006651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006652StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006653TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006654 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006655 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006656 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006657 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006658
Douglas Gregor96c79492010-04-23 22:50:49 +00006659 // Transform the @catch statements (if present).
6660 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006661 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006662 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006663 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006664 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006666 if (Catch.get() != S->getCatchStmt(I))
6667 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006668 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006669 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006670
Douglas Gregor306de2f2010-04-22 23:59:56 +00006671 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006672 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006673 if (S->getFinallyStmt()) {
6674 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6675 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006677 }
6678
6679 // If nothing changed, just retain this statement.
6680 if (!getDerived().AlwaysRebuild() &&
6681 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006682 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006683 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006684 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006685
Douglas Gregor306de2f2010-04-22 23:59:56 +00006686 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006687 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006688 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006689}
Mike Stump11289f42009-09-09 15:08:12 +00006690
Douglas Gregorebe10102009-08-20 07:17:43 +00006691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006693TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006694 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006695 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006696 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006697 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006698 if (FromVar->getTypeSourceInfo()) {
6699 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6700 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006701 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006702 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006703
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006704 QualType T;
6705 if (TSInfo)
6706 T = TSInfo->getType();
6707 else {
6708 T = getDerived().TransformType(FromVar->getType());
6709 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006710 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006711 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006712
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006713 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6714 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006715 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
John McCalldadc5752010-08-24 06:29:42 +00006718 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006719 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006720 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006721
6722 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006723 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006724 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006725}
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregorebe10102009-08-20 07:17:43 +00006727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006728StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006729TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006730 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006731 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006732 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregor306de2f2010-04-22 23:59:56 +00006735 // If nothing changed, just retain this statement.
6736 if (!getDerived().AlwaysRebuild() &&
6737 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006738 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006739
6740 // Build a new statement.
6741 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006742 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006743}
Mike Stump11289f42009-09-09 15:08:12 +00006744
Douglas Gregorebe10102009-08-20 07:17:43 +00006745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006746StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006747TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006748 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006749 if (S->getThrowExpr()) {
6750 Operand = getDerived().TransformExpr(S->getThrowExpr());
6751 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006752 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006754
Douglas Gregor2900c162010-04-22 21:44:01 +00006755 if (!getDerived().AlwaysRebuild() &&
6756 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006757 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006758
John McCallb268a282010-08-23 23:25:46 +00006759 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006760}
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregorebe10102009-08-20 07:17:43 +00006762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006763StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006764TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006765 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006766 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006767 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006768 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006770 Object =
6771 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6772 Object.get());
6773 if (Object.isInvalid())
6774 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Douglas Gregor6148de72010-04-22 22:01:21 +00006776 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006777 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006778 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006779 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
Douglas Gregor6148de72010-04-22 22:01:21 +00006781 // If nothing change, just retain the current statement.
6782 if (!getDerived().AlwaysRebuild() &&
6783 Object.get() == S->getSynchExpr() &&
6784 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006785 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006786
6787 // Build a new statement.
6788 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006789 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006790}
6791
6792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006793StmtResult
John McCall31168b02011-06-15 23:02:42 +00006794TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6795 ObjCAutoreleasePoolStmt *S) {
6796 // Transform the body.
6797 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6798 if (Body.isInvalid())
6799 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006800
John McCall31168b02011-06-15 23:02:42 +00006801 // If nothing changed, just retain this statement.
6802 if (!getDerived().AlwaysRebuild() &&
6803 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006804 return S;
John McCall31168b02011-06-15 23:02:42 +00006805
6806 // Build a new statement.
6807 return getDerived().RebuildObjCAutoreleasePoolStmt(
6808 S->getAtLoc(), Body.get());
6809}
6810
6811template<typename Derived>
6812StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006813TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006814 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006815 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006816 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006817 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006818 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006819
Douglas Gregorf68a5082010-04-22 23:10:45 +00006820 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006821 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006822 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006824
Douglas Gregorf68a5082010-04-22 23:10:45 +00006825 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006826 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006827 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006829
Douglas Gregorf68a5082010-04-22 23:10:45 +00006830 // If nothing changed, just retain this statement.
6831 if (!getDerived().AlwaysRebuild() &&
6832 Element.get() == S->getElement() &&
6833 Collection.get() == S->getCollection() &&
6834 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006835 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006836
Douglas Gregorf68a5082010-04-22 23:10:45 +00006837 // Build a new statement.
6838 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006839 Element.get(),
6840 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006841 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006842 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006843}
6844
David Majnemer5f7efef2013-10-15 09:50:08 +00006845template <typename Derived>
6846StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006847 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006848 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006849 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6850 TypeSourceInfo *T =
6851 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006852 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
David Majnemer5f7efef2013-10-15 09:50:08 +00006855 Var = getDerived().RebuildExceptionDecl(
6856 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6857 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006858 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 }
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregorebe10102009-08-20 07:17:43 +00006862 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006863 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006864 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006865 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006866
David Majnemer5f7efef2013-10-15 09:50:08 +00006867 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006868 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006869 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006870
David Majnemer5f7efef2013-10-15 09:50:08 +00006871 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006872}
Mike Stump11289f42009-09-09 15:08:12 +00006873
David Majnemer5f7efef2013-10-15 09:50:08 +00006874template <typename Derived>
6875StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006876 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006877 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006878 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregorebe10102009-08-20 07:17:43 +00006881 // Transform the handlers.
6882 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006883 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006884 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006885 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006886 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006888
Douglas Gregorebe10102009-08-20 07:17:43 +00006889 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006890 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006891 }
Mike Stump11289f42009-09-09 15:08:12 +00006892
David Majnemer5f7efef2013-10-15 09:50:08 +00006893 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006894 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006895 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006896
John McCallb268a282010-08-23 23:25:46 +00006897 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006898 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006899}
Mike Stump11289f42009-09-09 15:08:12 +00006900
Richard Smith02e85f32011-04-14 22:09:26 +00006901template<typename Derived>
6902StmtResult
6903TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6904 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6905 if (Range.isInvalid())
6906 return StmtError();
6907
Richard Smith01694c32016-03-20 10:33:40 +00006908 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6909 if (Begin.isInvalid())
6910 return StmtError();
6911 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6912 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006913 return StmtError();
6914
6915 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6916 if (Cond.isInvalid())
6917 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006918 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006919 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006920 if (Cond.isInvalid())
6921 return StmtError();
6922 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006923 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006924
6925 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6926 if (Inc.isInvalid())
6927 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006928 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006929 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006930
6931 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6932 if (LoopVar.isInvalid())
6933 return StmtError();
6934
6935 StmtResult NewStmt = S;
6936 if (getDerived().AlwaysRebuild() ||
6937 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006938 Begin.get() != S->getBeginStmt() ||
6939 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006940 Cond.get() != S->getCond() ||
6941 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006942 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006943 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006944 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006945 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006946 Begin.get(), End.get(),
6947 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006948 Inc.get(), LoopVar.get(),
6949 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006950 if (NewStmt.isInvalid())
6951 return StmtError();
6952 }
Richard Smith02e85f32011-04-14 22:09:26 +00006953
6954 StmtResult Body = getDerived().TransformStmt(S->getBody());
6955 if (Body.isInvalid())
6956 return StmtError();
6957
6958 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6959 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006960 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006961 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006962 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006963 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00006964 Begin.get(), End.get(),
6965 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00006966 Inc.get(), LoopVar.get(),
6967 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006968 if (NewStmt.isInvalid())
6969 return StmtError();
6970 }
Richard Smith02e85f32011-04-14 22:09:26 +00006971
6972 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006973 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006974
6975 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6976}
6977
John Wiegley1c0675e2011-04-28 01:08:34 +00006978template<typename Derived>
6979StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006980TreeTransform<Derived>::TransformMSDependentExistsStmt(
6981 MSDependentExistsStmt *S) {
6982 // Transform the nested-name-specifier, if any.
6983 NestedNameSpecifierLoc QualifierLoc;
6984 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006985 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006986 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6987 if (!QualifierLoc)
6988 return StmtError();
6989 }
6990
6991 // Transform the declaration name.
6992 DeclarationNameInfo NameInfo = S->getNameInfo();
6993 if (NameInfo.getName()) {
6994 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6995 if (!NameInfo.getName())
6996 return StmtError();
6997 }
6998
6999 // Check whether anything changed.
7000 if (!getDerived().AlwaysRebuild() &&
7001 QualifierLoc == S->getQualifierLoc() &&
7002 NameInfo.getName() == S->getNameInfo().getName())
7003 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007004
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007005 // Determine whether this name exists, if we can.
7006 CXXScopeSpec SS;
7007 SS.Adopt(QualifierLoc);
7008 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007009 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007010 case Sema::IER_Exists:
7011 if (S->isIfExists())
7012 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007013
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007014 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7015
7016 case Sema::IER_DoesNotExist:
7017 if (S->isIfNotExists())
7018 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007019
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007020 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007021
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007022 case Sema::IER_Dependent:
7023 Dependent = true;
7024 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007025
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007026 case Sema::IER_Error:
7027 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007029
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007030 // We need to continue with the instantiation, so do so now.
7031 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7032 if (SubStmt.isInvalid())
7033 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007034
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007035 // If we have resolved the name, just transform to the substatement.
7036 if (!Dependent)
7037 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007038
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007039 // The name is still dependent, so build a dependent expression again.
7040 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7041 S->isIfExists(),
7042 QualifierLoc,
7043 NameInfo,
7044 SubStmt.get());
7045}
7046
7047template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007048ExprResult
7049TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7050 NestedNameSpecifierLoc QualifierLoc;
7051 if (E->getQualifierLoc()) {
7052 QualifierLoc
7053 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7054 if (!QualifierLoc)
7055 return ExprError();
7056 }
7057
7058 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7059 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7060 if (!PD)
7061 return ExprError();
7062
7063 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7064 if (Base.isInvalid())
7065 return ExprError();
7066
7067 return new (SemaRef.getASTContext())
7068 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7069 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7070 QualifierLoc, E->getMemberLoc());
7071}
7072
David Majnemerfad8f482013-10-15 09:33:02 +00007073template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007074ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7075 MSPropertySubscriptExpr *E) {
7076 auto BaseRes = getDerived().TransformExpr(E->getBase());
7077 if (BaseRes.isInvalid())
7078 return ExprError();
7079 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7080 if (IdxRes.isInvalid())
7081 return ExprError();
7082
7083 if (!getDerived().AlwaysRebuild() &&
7084 BaseRes.get() == E->getBase() &&
7085 IdxRes.get() == E->getIdx())
7086 return E;
7087
7088 return getDerived().RebuildArraySubscriptExpr(
7089 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7090}
7091
7092template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007093StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007094 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007095 if (TryBlock.isInvalid())
7096 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007097
7098 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007099 if (Handler.isInvalid())
7100 return StmtError();
7101
David Majnemerfad8f482013-10-15 09:33:02 +00007102 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7103 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007104 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007105
Warren Huntf6be4cb2014-07-25 20:52:51 +00007106 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7107 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007108}
7109
David Majnemerfad8f482013-10-15 09:33:02 +00007110template <typename Derived>
7111StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007112 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007113 if (Block.isInvalid())
7114 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007115
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007116 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007117}
7118
David Majnemerfad8f482013-10-15 09:33:02 +00007119template <typename Derived>
7120StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007121 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007122 if (FilterExpr.isInvalid())
7123 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007124
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().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7130 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007131}
7132
David Majnemerfad8f482013-10-15 09:33:02 +00007133template <typename Derived>
7134StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7135 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007136 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7137 else
7138 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7139}
7140
Nico Weber9b982072014-07-07 00:12:30 +00007141template<typename Derived>
7142StmtResult
7143TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7144 return S;
7145}
7146
Alexander Musman64d33f12014-06-04 07:53:32 +00007147//===----------------------------------------------------------------------===//
7148// OpenMP directive transformation
7149//===----------------------------------------------------------------------===//
7150template <typename Derived>
7151StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7152 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007153
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007154 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007155 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007156 ArrayRef<OMPClause *> Clauses = D->clauses();
7157 TClauses.reserve(Clauses.size());
7158 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7159 I != E; ++I) {
7160 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007161 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007162 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007163 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007164 if (Clause)
7165 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007166 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007167 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007168 }
7169 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007170 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007171 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007172 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7173 /*CurScope=*/nullptr);
7174 StmtResult Body;
7175 {
7176 Sema::CompoundScopeRAII CompoundScope(getSema());
7177 Body = getDerived().TransformStmt(
7178 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7179 }
7180 AssociatedStmt =
7181 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007182 if (AssociatedStmt.isInvalid()) {
7183 return StmtError();
7184 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007185 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007186 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007187 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007188 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007189
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007190 // Transform directive name for 'omp critical' directive.
7191 DeclarationNameInfo DirName;
7192 if (D->getDirectiveKind() == OMPD_critical) {
7193 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7194 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7195 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007196 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7197 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7198 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007199 } else if (D->getDirectiveKind() == OMPD_cancel) {
7200 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007201 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007202
Alexander Musman64d33f12014-06-04 07:53:32 +00007203 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007204 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7205 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007206}
7207
Alexander Musman64d33f12014-06-04 07:53:32 +00007208template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007209StmtResult
7210TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7211 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007212 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7213 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007214 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7215 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7216 return Res;
7217}
7218
Alexander Musman64d33f12014-06-04 07:53:32 +00007219template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007220StmtResult
7221TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7222 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007223 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7224 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007225 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7226 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007227 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007228}
7229
Alexey Bataevf29276e2014-06-18 04:14:57 +00007230template <typename Derived>
7231StmtResult
7232TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7233 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007234 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7235 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007236 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7237 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7238 return Res;
7239}
7240
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007241template <typename Derived>
7242StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007243TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7244 DeclarationNameInfo DirName;
7245 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7246 D->getLocStart());
7247 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7248 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7249 return Res;
7250}
7251
7252template <typename Derived>
7253StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007254TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7255 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007256 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7257 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007258 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7259 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7260 return Res;
7261}
7262
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007263template <typename Derived>
7264StmtResult
7265TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7266 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007267 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7268 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007269 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7270 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7271 return Res;
7272}
7273
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007274template <typename Derived>
7275StmtResult
7276TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7277 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007278 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7279 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007280 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7281 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7282 return Res;
7283}
7284
Alexey Bataev4acb8592014-07-07 13:01:15 +00007285template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007286StmtResult
7287TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7288 DeclarationNameInfo DirName;
7289 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7290 D->getLocStart());
7291 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7292 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7293 return Res;
7294}
7295
7296template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007297StmtResult
7298TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7299 getDerived().getSema().StartOpenMPDSABlock(
7300 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7301 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7302 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7303 return Res;
7304}
7305
7306template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007307StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7308 OMPParallelForDirective *D) {
7309 DeclarationNameInfo DirName;
7310 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7311 nullptr, D->getLocStart());
7312 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7313 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7314 return Res;
7315}
7316
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007317template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007318StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7319 OMPParallelForSimdDirective *D) {
7320 DeclarationNameInfo DirName;
7321 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7322 nullptr, D->getLocStart());
7323 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7324 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7325 return Res;
7326}
7327
7328template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007329StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7330 OMPParallelSectionsDirective *D) {
7331 DeclarationNameInfo DirName;
7332 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7333 nullptr, D->getLocStart());
7334 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7335 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7336 return Res;
7337}
7338
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007339template <typename Derived>
7340StmtResult
7341TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7342 DeclarationNameInfo DirName;
7343 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7344 D->getLocStart());
7345 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7346 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7347 return Res;
7348}
7349
Alexey Bataev68446b72014-07-18 07:47:19 +00007350template <typename Derived>
7351StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7352 OMPTaskyieldDirective *D) {
7353 DeclarationNameInfo DirName;
7354 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7355 D->getLocStart());
7356 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7357 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7358 return Res;
7359}
7360
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007361template <typename Derived>
7362StmtResult
7363TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7364 DeclarationNameInfo DirName;
7365 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7366 D->getLocStart());
7367 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7368 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7369 return Res;
7370}
7371
Alexey Bataev2df347a2014-07-18 10:17:07 +00007372template <typename Derived>
7373StmtResult
7374TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7375 DeclarationNameInfo DirName;
7376 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7377 D->getLocStart());
7378 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7379 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7380 return Res;
7381}
7382
Alexey Bataev6125da92014-07-21 11:26:11 +00007383template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007384StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7385 OMPTaskgroupDirective *D) {
7386 DeclarationNameInfo DirName;
7387 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7388 D->getLocStart());
7389 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7390 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7391 return Res;
7392}
7393
7394template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007395StmtResult
7396TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7397 DeclarationNameInfo DirName;
7398 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7399 D->getLocStart());
7400 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7401 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7402 return Res;
7403}
7404
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007405template <typename Derived>
7406StmtResult
7407TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7408 DeclarationNameInfo DirName;
7409 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7410 D->getLocStart());
7411 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7412 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7413 return Res;
7414}
7415
Alexey Bataev0162e452014-07-22 10:10:35 +00007416template <typename Derived>
7417StmtResult
7418TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7419 DeclarationNameInfo DirName;
7420 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7421 D->getLocStart());
7422 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7423 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7424 return Res;
7425}
7426
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007427template <typename Derived>
7428StmtResult
7429TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7430 DeclarationNameInfo DirName;
7431 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7432 D->getLocStart());
7433 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7434 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7435 return Res;
7436}
7437
Alexey Bataev13314bf2014-10-09 04:18:56 +00007438template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007439StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7440 OMPTargetDataDirective *D) {
7441 DeclarationNameInfo DirName;
7442 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7443 D->getLocStart());
7444 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7445 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7446 return Res;
7447}
7448
7449template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007450StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7451 OMPTargetEnterDataDirective *D) {
7452 DeclarationNameInfo DirName;
7453 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7454 nullptr, D->getLocStart());
7455 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7456 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7457 return Res;
7458}
7459
7460template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007461StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7462 OMPTargetExitDataDirective *D) {
7463 DeclarationNameInfo DirName;
7464 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7465 nullptr, D->getLocStart());
7466 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7467 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7468 return Res;
7469}
7470
7471template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007472StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7473 OMPTargetParallelDirective *D) {
7474 DeclarationNameInfo DirName;
7475 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7476 nullptr, D->getLocStart());
7477 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7478 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7479 return Res;
7480}
7481
7482template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007483StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7484 OMPTargetParallelForDirective *D) {
7485 DeclarationNameInfo DirName;
7486 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7487 nullptr, D->getLocStart());
7488 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7489 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7490 return Res;
7491}
7492
7493template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007494StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7495 OMPTargetUpdateDirective *D) {
7496 DeclarationNameInfo DirName;
7497 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7498 nullptr, D->getLocStart());
7499 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7500 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7501 return Res;
7502}
7503
7504template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007505StmtResult
7506TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7507 DeclarationNameInfo DirName;
7508 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7509 D->getLocStart());
7510 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7511 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7512 return Res;
7513}
7514
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007515template <typename Derived>
7516StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7517 OMPCancellationPointDirective *D) {
7518 DeclarationNameInfo DirName;
7519 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7520 nullptr, D->getLocStart());
7521 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7522 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7523 return Res;
7524}
7525
Alexey Bataev80909872015-07-02 11:25:17 +00007526template <typename Derived>
7527StmtResult
7528TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7529 DeclarationNameInfo DirName;
7530 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7531 D->getLocStart());
7532 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7533 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7534 return Res;
7535}
7536
Alexey Bataev49f6e782015-12-01 04:18:41 +00007537template <typename Derived>
7538StmtResult
7539TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7540 DeclarationNameInfo DirName;
7541 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7542 D->getLocStart());
7543 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7544 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7545 return Res;
7546}
7547
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007548template <typename Derived>
7549StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7550 OMPTaskLoopSimdDirective *D) {
7551 DeclarationNameInfo DirName;
7552 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7553 nullptr, D->getLocStart());
7554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7555 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7556 return Res;
7557}
7558
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007559template <typename Derived>
7560StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7561 OMPDistributeDirective *D) {
7562 DeclarationNameInfo DirName;
7563 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7564 D->getLocStart());
7565 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7566 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7567 return Res;
7568}
7569
Carlo Bertolli9925f152016-06-27 14:55:37 +00007570template <typename Derived>
7571StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7572 OMPDistributeParallelForDirective *D) {
7573 DeclarationNameInfo DirName;
7574 getDerived().getSema().StartOpenMPDSABlock(
7575 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7576 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7577 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7578 return Res;
7579}
7580
Kelvin Li4a39add2016-07-05 05:00:15 +00007581template <typename Derived>
7582StmtResult
7583TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7584 OMPDistributeParallelForSimdDirective *D) {
7585 DeclarationNameInfo DirName;
7586 getDerived().getSema().StartOpenMPDSABlock(
7587 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7588 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7589 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7590 return Res;
7591}
7592
Kelvin Li787f3fc2016-07-06 04:45:38 +00007593template <typename Derived>
7594StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7595 OMPDistributeSimdDirective *D) {
7596 DeclarationNameInfo DirName;
7597 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7598 nullptr, D->getLocStart());
7599 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7600 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7601 return Res;
7602}
7603
Alexander Musman64d33f12014-06-04 07:53:32 +00007604//===----------------------------------------------------------------------===//
7605// OpenMP clause transformation
7606//===----------------------------------------------------------------------===//
7607template <typename Derived>
7608OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007609 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7610 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007611 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007612 return getDerived().RebuildOMPIfClause(
7613 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7614 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007615}
7616
Alexander Musman64d33f12014-06-04 07:53:32 +00007617template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007618OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7619 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7620 if (Cond.isInvalid())
7621 return nullptr;
7622 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7623 C->getLParenLoc(), C->getLocEnd());
7624}
7625
7626template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007627OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007628TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7629 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7630 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007631 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007632 return getDerived().RebuildOMPNumThreadsClause(
7633 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007634}
7635
Alexey Bataev62c87d22014-03-21 04:51:18 +00007636template <typename Derived>
7637OMPClause *
7638TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7639 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7640 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007641 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007642 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007643 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007644}
7645
Alexander Musman8bd31e62014-05-27 15:12:19 +00007646template <typename Derived>
7647OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007648TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7649 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7650 if (E.isInvalid())
7651 return nullptr;
7652 return getDerived().RebuildOMPSimdlenClause(
7653 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7654}
7655
7656template <typename Derived>
7657OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007658TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7659 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7660 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007661 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007662 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007663 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007664}
7665
Alexander Musman64d33f12014-06-04 07:53:32 +00007666template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007667OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007668TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007669 return getDerived().RebuildOMPDefaultClause(
7670 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7671 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007672}
7673
Alexander Musman64d33f12014-06-04 07:53:32 +00007674template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007675OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007676TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007677 return getDerived().RebuildOMPProcBindClause(
7678 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7679 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007680}
7681
Alexander Musman64d33f12014-06-04 07:53:32 +00007682template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007683OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007684TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7685 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7686 if (E.isInvalid())
7687 return nullptr;
7688 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007689 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007690 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007691 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007692 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7693}
7694
7695template <typename Derived>
7696OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007697TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007698 ExprResult E;
7699 if (auto *Num = C->getNumForLoops()) {
7700 E = getDerived().TransformExpr(Num);
7701 if (E.isInvalid())
7702 return nullptr;
7703 }
7704 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7705 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007706}
7707
7708template <typename Derived>
7709OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007710TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7711 // No need to rebuild this clause, no template-dependent parameters.
7712 return C;
7713}
7714
7715template <typename Derived>
7716OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007717TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7718 // No need to rebuild this clause, no template-dependent parameters.
7719 return C;
7720}
7721
7722template <typename Derived>
7723OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007724TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7725 // No need to rebuild this clause, no template-dependent parameters.
7726 return C;
7727}
7728
7729template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007730OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7731 // No need to rebuild this clause, no template-dependent parameters.
7732 return C;
7733}
7734
7735template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007736OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7737 // No need to rebuild this clause, no template-dependent parameters.
7738 return C;
7739}
7740
7741template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007742OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007743TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7744 // No need to rebuild this clause, no template-dependent parameters.
7745 return C;
7746}
7747
7748template <typename Derived>
7749OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007750TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7751 // No need to rebuild this clause, no template-dependent parameters.
7752 return C;
7753}
7754
7755template <typename Derived>
7756OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007757TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7758 // No need to rebuild this clause, no template-dependent parameters.
7759 return C;
7760}
7761
7762template <typename Derived>
7763OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007764TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7765 // No need to rebuild this clause, no template-dependent parameters.
7766 return C;
7767}
7768
7769template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007770OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7771 // No need to rebuild this clause, no template-dependent parameters.
7772 return C;
7773}
7774
7775template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007776OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007777TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7778 // No need to rebuild this clause, no template-dependent parameters.
7779 return C;
7780}
7781
7782template <typename Derived>
7783OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007784TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007785 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007786 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007787 for (auto *VE : C->varlists()) {
7788 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007789 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007790 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007791 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007792 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007793 return getDerived().RebuildOMPPrivateClause(
7794 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007795}
7796
Alexander Musman64d33f12014-06-04 07:53:32 +00007797template <typename Derived>
7798OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7799 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007800 llvm::SmallVector<Expr *, 16> Vars;
7801 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007802 for (auto *VE : C->varlists()) {
7803 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007804 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007805 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007806 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007807 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007808 return getDerived().RebuildOMPFirstprivateClause(
7809 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007810}
7811
Alexander Musman64d33f12014-06-04 07:53:32 +00007812template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007813OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007814TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7815 llvm::SmallVector<Expr *, 16> Vars;
7816 Vars.reserve(C->varlist_size());
7817 for (auto *VE : C->varlists()) {
7818 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7819 if (EVar.isInvalid())
7820 return nullptr;
7821 Vars.push_back(EVar.get());
7822 }
7823 return getDerived().RebuildOMPLastprivateClause(
7824 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7825}
7826
7827template <typename Derived>
7828OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007829TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7830 llvm::SmallVector<Expr *, 16> Vars;
7831 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007832 for (auto *VE : C->varlists()) {
7833 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007834 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007835 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007836 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007837 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007838 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7839 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007840}
7841
Alexander Musman64d33f12014-06-04 07:53:32 +00007842template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007843OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007844TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7845 llvm::SmallVector<Expr *, 16> Vars;
7846 Vars.reserve(C->varlist_size());
7847 for (auto *VE : C->varlists()) {
7848 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7849 if (EVar.isInvalid())
7850 return nullptr;
7851 Vars.push_back(EVar.get());
7852 }
7853 CXXScopeSpec ReductionIdScopeSpec;
7854 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7855
7856 DeclarationNameInfo NameInfo = C->getNameInfo();
7857 if (NameInfo.getName()) {
7858 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7859 if (!NameInfo.getName())
7860 return nullptr;
7861 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007862 // Build a list of all UDR decls with the same names ranged by the Scopes.
7863 // The Scope boundary is a duplication of the previous decl.
7864 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7865 for (auto *E : C->reduction_ops()) {
7866 // Transform all the decls.
7867 if (E) {
7868 auto *ULE = cast<UnresolvedLookupExpr>(E);
7869 UnresolvedSet<8> Decls;
7870 for (auto *D : ULE->decls()) {
7871 NamedDecl *InstD =
7872 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7873 Decls.addDecl(InstD, InstD->getAccess());
7874 }
7875 UnresolvedReductions.push_back(
7876 UnresolvedLookupExpr::Create(
7877 SemaRef.Context, /*NamingClass=*/nullptr,
7878 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7879 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7880 Decls.begin(), Decls.end()));
7881 } else
7882 UnresolvedReductions.push_back(nullptr);
7883 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00007884 return getDerived().RebuildOMPReductionClause(
7885 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007886 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00007887}
7888
7889template <typename Derived>
7890OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007891TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7892 llvm::SmallVector<Expr *, 16> Vars;
7893 Vars.reserve(C->varlist_size());
7894 for (auto *VE : C->varlists()) {
7895 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7896 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007897 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007898 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007899 }
7900 ExprResult Step = getDerived().TransformExpr(C->getStep());
7901 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007902 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007903 return getDerived().RebuildOMPLinearClause(
7904 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7905 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007906}
7907
Alexander Musman64d33f12014-06-04 07:53:32 +00007908template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007909OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007910TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7911 llvm::SmallVector<Expr *, 16> Vars;
7912 Vars.reserve(C->varlist_size());
7913 for (auto *VE : C->varlists()) {
7914 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7915 if (EVar.isInvalid())
7916 return nullptr;
7917 Vars.push_back(EVar.get());
7918 }
7919 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7920 if (Alignment.isInvalid())
7921 return nullptr;
7922 return getDerived().RebuildOMPAlignedClause(
7923 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7924 C->getColonLoc(), C->getLocEnd());
7925}
7926
Alexander Musman64d33f12014-06-04 07:53:32 +00007927template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007928OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007929TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7930 llvm::SmallVector<Expr *, 16> Vars;
7931 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007932 for (auto *VE : C->varlists()) {
7933 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007934 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007935 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007936 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007937 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007938 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7939 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007940}
7941
Alexey Bataevbae9a792014-06-27 10:37:06 +00007942template <typename Derived>
7943OMPClause *
7944TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7945 llvm::SmallVector<Expr *, 16> Vars;
7946 Vars.reserve(C->varlist_size());
7947 for (auto *VE : C->varlists()) {
7948 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7949 if (EVar.isInvalid())
7950 return nullptr;
7951 Vars.push_back(EVar.get());
7952 }
7953 return getDerived().RebuildOMPCopyprivateClause(
7954 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7955}
7956
Alexey Bataev6125da92014-07-21 11:26:11 +00007957template <typename Derived>
7958OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7959 llvm::SmallVector<Expr *, 16> Vars;
7960 Vars.reserve(C->varlist_size());
7961 for (auto *VE : C->varlists()) {
7962 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7963 if (EVar.isInvalid())
7964 return nullptr;
7965 Vars.push_back(EVar.get());
7966 }
7967 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7968 C->getLParenLoc(), C->getLocEnd());
7969}
7970
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007971template <typename Derived>
7972OMPClause *
7973TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7974 llvm::SmallVector<Expr *, 16> Vars;
7975 Vars.reserve(C->varlist_size());
7976 for (auto *VE : C->varlists()) {
7977 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7978 if (EVar.isInvalid())
7979 return nullptr;
7980 Vars.push_back(EVar.get());
7981 }
7982 return getDerived().RebuildOMPDependClause(
7983 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7984 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7985}
7986
Michael Wonge710d542015-08-07 16:16:36 +00007987template <typename Derived>
7988OMPClause *
7989TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7990 ExprResult E = getDerived().TransformExpr(C->getDevice());
7991 if (E.isInvalid())
7992 return nullptr;
7993 return getDerived().RebuildOMPDeviceClause(
7994 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7995}
7996
Kelvin Li0bff7af2015-11-23 05:32:03 +00007997template <typename Derived>
7998OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7999 llvm::SmallVector<Expr *, 16> Vars;
8000 Vars.reserve(C->varlist_size());
8001 for (auto *VE : C->varlists()) {
8002 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8003 if (EVar.isInvalid())
8004 return nullptr;
8005 Vars.push_back(EVar.get());
8006 }
8007 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008008 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8009 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8010 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008011}
8012
Kelvin Li099bb8c2015-11-24 20:50:12 +00008013template <typename Derived>
8014OMPClause *
8015TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8016 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8017 if (E.isInvalid())
8018 return nullptr;
8019 return getDerived().RebuildOMPNumTeamsClause(
8020 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8021}
8022
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008023template <typename Derived>
8024OMPClause *
8025TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8026 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8027 if (E.isInvalid())
8028 return nullptr;
8029 return getDerived().RebuildOMPThreadLimitClause(
8030 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8031}
8032
Alexey Bataeva0569352015-12-01 10:17:31 +00008033template <typename Derived>
8034OMPClause *
8035TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8036 ExprResult E = getDerived().TransformExpr(C->getPriority());
8037 if (E.isInvalid())
8038 return nullptr;
8039 return getDerived().RebuildOMPPriorityClause(
8040 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8041}
8042
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008043template <typename Derived>
8044OMPClause *
8045TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8046 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8047 if (E.isInvalid())
8048 return nullptr;
8049 return getDerived().RebuildOMPGrainsizeClause(
8050 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8051}
8052
Alexey Bataev382967a2015-12-08 12:06:20 +00008053template <typename Derived>
8054OMPClause *
8055TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8056 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8057 if (E.isInvalid())
8058 return nullptr;
8059 return getDerived().RebuildOMPNumTasksClause(
8060 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8061}
8062
Alexey Bataev28c75412015-12-15 08:19:24 +00008063template <typename Derived>
8064OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8065 ExprResult E = getDerived().TransformExpr(C->getHint());
8066 if (E.isInvalid())
8067 return nullptr;
8068 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8069 C->getLParenLoc(), C->getLocEnd());
8070}
8071
Carlo Bertollib4adf552016-01-15 18:50:31 +00008072template <typename Derived>
8073OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8074 OMPDistScheduleClause *C) {
8075 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8076 if (E.isInvalid())
8077 return nullptr;
8078 return getDerived().RebuildOMPDistScheduleClause(
8079 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8080 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8081}
8082
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008083template <typename Derived>
8084OMPClause *
8085TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8086 return C;
8087}
8088
Samuel Antao661c0902016-05-26 17:39:58 +00008089template <typename Derived>
8090OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8091 llvm::SmallVector<Expr *, 16> Vars;
8092 Vars.reserve(C->varlist_size());
8093 for (auto *VE : C->varlists()) {
8094 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8095 if (EVar.isInvalid())
8096 return 0;
8097 Vars.push_back(EVar.get());
8098 }
8099 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8100 C->getLParenLoc(), C->getLocEnd());
8101}
8102
Samuel Antaoec172c62016-05-26 17:49:04 +00008103template <typename Derived>
8104OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8105 llvm::SmallVector<Expr *, 16> Vars;
8106 Vars.reserve(C->varlist_size());
8107 for (auto *VE : C->varlists()) {
8108 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8109 if (EVar.isInvalid())
8110 return 0;
8111 Vars.push_back(EVar.get());
8112 }
8113 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8114 C->getLParenLoc(), C->getLocEnd());
8115}
8116
Carlo Bertolli2404b172016-07-13 15:37:16 +00008117template <typename Derived>
8118OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8119 OMPUseDevicePtrClause *C) {
8120 llvm::SmallVector<Expr *, 16> Vars;
8121 Vars.reserve(C->varlist_size());
8122 for (auto *VE : C->varlists()) {
8123 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8124 if (EVar.isInvalid())
8125 return nullptr;
8126 Vars.push_back(EVar.get());
8127 }
8128 return getDerived().RebuildOMPUseDevicePtrClause(
8129 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8130}
8131
Carlo Bertolli70594e92016-07-13 17:16:49 +00008132template <typename Derived>
8133OMPClause *
8134TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8135 llvm::SmallVector<Expr *, 16> Vars;
8136 Vars.reserve(C->varlist_size());
8137 for (auto *VE : C->varlists()) {
8138 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8139 if (EVar.isInvalid())
8140 return nullptr;
8141 Vars.push_back(EVar.get());
8142 }
8143 return getDerived().RebuildOMPIsDevicePtrClause(
8144 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8145}
8146
Douglas Gregorebe10102009-08-20 07:17:43 +00008147//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008148// Expression transformation
8149//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008152TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008153 if (!E->isTypeDependent())
8154 return E;
8155
8156 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8157 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008158}
Mike Stump11289f42009-09-09 15:08:12 +00008159
8160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008162TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008163 NestedNameSpecifierLoc QualifierLoc;
8164 if (E->getQualifierLoc()) {
8165 QualifierLoc
8166 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8167 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008169 }
John McCallce546572009-12-08 09:08:17 +00008170
8171 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008172 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8173 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008176
John McCall815039a2010-08-17 21:27:17 +00008177 DeclarationNameInfo NameInfo = E->getNameInfo();
8178 if (NameInfo.getName()) {
8179 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8180 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008181 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008182 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008183
8184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008185 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008186 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008187 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008188 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008189
8190 // Mark it referenced in the new context regardless.
8191 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008192 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008193
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008194 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008195 }
John McCallce546572009-12-08 09:08:17 +00008196
Craig Topperc3ec1492014-05-26 06:22:03 +00008197 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008198 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008199 TemplateArgs = &TransArgs;
8200 TransArgs.setLAngleLoc(E->getLAngleLoc());
8201 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008202 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8203 E->getNumTemplateArgs(),
8204 TransArgs))
8205 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008206 }
8207
Chad Rosier1dcde962012-08-08 18:46:20 +00008208 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008209 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008210}
Mike Stump11289f42009-09-09 15:08:12 +00008211
Douglas Gregora16548e2009-08-11 05:31:07 +00008212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008214TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008215 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008216}
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008220TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008221 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008222}
Mike Stump11289f42009-09-09 15:08:12 +00008223
Douglas Gregora16548e2009-08-11 05:31:07 +00008224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008226TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008227 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008228}
Mike Stump11289f42009-09-09 15:08:12 +00008229
Douglas Gregora16548e2009-08-11 05:31:07 +00008230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008232TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008233 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008234}
Mike Stump11289f42009-09-09 15:08:12 +00008235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008238TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008239 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008240}
8241
8242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008243ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008244TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008245 if (FunctionDecl *FD = E->getDirectCallee())
8246 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008247 return SemaRef.MaybeBindToTemporary(E);
8248}
8249
8250template<typename Derived>
8251ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008252TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8253 ExprResult ControllingExpr =
8254 getDerived().TransformExpr(E->getControllingExpr());
8255 if (ControllingExpr.isInvalid())
8256 return ExprError();
8257
Chris Lattner01cf8db2011-07-20 06:58:45 +00008258 SmallVector<Expr *, 4> AssocExprs;
8259 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008260 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8261 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8262 if (TS) {
8263 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8264 if (!AssocType)
8265 return ExprError();
8266 AssocTypes.push_back(AssocType);
8267 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008268 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008269 }
8270
8271 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8272 if (AssocExpr.isInvalid())
8273 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008274 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008275 }
8276
8277 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8278 E->getDefaultLoc(),
8279 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008280 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008281 AssocTypes,
8282 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008283}
8284
8285template<typename Derived>
8286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008287TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008288 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008289 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008291
Douglas Gregora16548e2009-08-11 05:31:07 +00008292 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008293 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008294
John McCallb268a282010-08-23 23:25:46 +00008295 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 E->getRParen());
8297}
8298
Richard Smithdb2630f2012-10-21 03:28:35 +00008299/// \brief The operand of a unary address-of operator has special rules: it's
8300/// allowed to refer to a non-static member of a class even if there's no 'this'
8301/// object available.
8302template<typename Derived>
8303ExprResult
8304TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8305 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008306 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008307 else
8308 return getDerived().TransformExpr(E);
8309}
8310
Mike Stump11289f42009-09-09 15:08:12 +00008311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008313TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008314 ExprResult SubExpr;
8315 if (E->getOpcode() == UO_AddrOf)
8316 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8317 else
8318 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008319 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008321
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008323 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008324
Douglas Gregora16548e2009-08-11 05:31:07 +00008325 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8326 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008327 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008328}
Mike Stump11289f42009-09-09 15:08:12 +00008329
Douglas Gregora16548e2009-08-11 05:31:07 +00008330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008331ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008332TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8333 // Transform the type.
8334 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8335 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008336 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008337
Douglas Gregor882211c2010-04-28 22:16:22 +00008338 // Transform all of the components into components similar to what the
8339 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008340 // FIXME: It would be slightly more efficient in the non-dependent case to
8341 // just map FieldDecls, rather than requiring the rebuilder to look for
8342 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008343 // template code that we don't care.
8344 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008345 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008346 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008347 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008348 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008349 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008350 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008351 Comp.LocStart = ON.getSourceRange().getBegin();
8352 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008353 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008354 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008355 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008356 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008357 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008359
Douglas Gregor882211c2010-04-28 22:16:22 +00008360 ExprChanged = ExprChanged || Index.get() != FromIndex;
8361 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008362 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008363 break;
8364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008365
James Y Knight7281c352015-12-29 22:31:18 +00008366 case OffsetOfNode::Field:
8367 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008368 Comp.isBrackets = false;
8369 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008370 if (!Comp.U.IdentInfo)
8371 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008372
Douglas Gregor882211c2010-04-28 22:16:22 +00008373 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008374
James Y Knight7281c352015-12-29 22:31:18 +00008375 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008376 // Will be recomputed during the rebuild.
8377 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008379
Douglas Gregor882211c2010-04-28 22:16:22 +00008380 Components.push_back(Comp);
8381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008382
Douglas Gregor882211c2010-04-28 22:16:22 +00008383 // If nothing changed, retain the existing expression.
8384 if (!getDerived().AlwaysRebuild() &&
8385 Type == E->getTypeSourceInfo() &&
8386 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008387 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008388
Douglas Gregor882211c2010-04-28 22:16:22 +00008389 // Build a new offsetof expression.
8390 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008391 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008392}
8393
8394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008395ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008396TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008397 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008398 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008399 return E;
John McCall8d69a212010-11-15 23:31:06 +00008400}
8401
8402template<typename Derived>
8403ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008404TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8405 return E;
8406}
8407
8408template<typename Derived>
8409ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008410TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008411 // Rebuild the syntactic form. The original syntactic form has
8412 // opaque-value expressions in it, so strip those away and rebuild
8413 // the result. This is a really awful way of doing this, but the
8414 // better solution (rebuilding the semantic expressions and
8415 // rebinding OVEs as necessary) doesn't work; we'd need
8416 // TreeTransform to not strip away implicit conversions.
8417 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8418 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008419 if (result.isInvalid()) return ExprError();
8420
8421 // If that gives us a pseudo-object result back, the pseudo-object
8422 // expression must have been an lvalue-to-rvalue conversion which we
8423 // should reapply.
8424 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008425 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008426
8427 return result;
8428}
8429
8430template<typename Derived>
8431ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008432TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8433 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008435 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008436
John McCallbcd03502009-12-07 02:54:59 +00008437 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008438 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008440
John McCall4c98fd82009-11-04 07:28:41 +00008441 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008442 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008443
Peter Collingbournee190dee2011-03-11 19:24:49 +00008444 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8445 E->getKind(),
8446 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008447 }
Mike Stump11289f42009-09-09 15:08:12 +00008448
Eli Friedmane4f22df2012-02-29 04:03:55 +00008449 // C++0x [expr.sizeof]p1:
8450 // The operand is either an expression, which is an unevaluated operand
8451 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008452 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8453 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008454
Reid Kleckner32506ed2014-06-12 23:03:48 +00008455 // Try to recover if we have something like sizeof(T::X) where X is a type.
8456 // Notably, there must be *exactly* one set of parens if X is a type.
8457 TypeSourceInfo *RecoveryTSI = nullptr;
8458 ExprResult SubExpr;
8459 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8460 if (auto *DRE =
8461 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8462 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8463 PE, DRE, false, &RecoveryTSI);
8464 else
8465 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8466
8467 if (RecoveryTSI) {
8468 return getDerived().RebuildUnaryExprOrTypeTrait(
8469 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8470 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008471 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008472
Eli Friedmane4f22df2012-02-29 04:03:55 +00008473 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008474 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008475
Peter Collingbournee190dee2011-03-11 19:24:49 +00008476 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8477 E->getOperatorLoc(),
8478 E->getKind(),
8479 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008480}
Mike Stump11289f42009-09-09 15:08:12 +00008481
Douglas Gregora16548e2009-08-11 05:31:07 +00008482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008483ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008484TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008485 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008486 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008488
John McCalldadc5752010-08-24 06:29:42 +00008489 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008492
8493
Douglas Gregora16548e2009-08-11 05:31:07 +00008494 if (!getDerived().AlwaysRebuild() &&
8495 LHS.get() == E->getLHS() &&
8496 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008497 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008498
John McCallb268a282010-08-23 23:25:46 +00008499 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008500 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008501 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 E->getRBracketLoc());
8503}
Mike Stump11289f42009-09-09 15:08:12 +00008504
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008505template <typename Derived>
8506ExprResult
8507TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8508 ExprResult Base = getDerived().TransformExpr(E->getBase());
8509 if (Base.isInvalid())
8510 return ExprError();
8511
8512 ExprResult LowerBound;
8513 if (E->getLowerBound()) {
8514 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8515 if (LowerBound.isInvalid())
8516 return ExprError();
8517 }
8518
8519 ExprResult Length;
8520 if (E->getLength()) {
8521 Length = getDerived().TransformExpr(E->getLength());
8522 if (Length.isInvalid())
8523 return ExprError();
8524 }
8525
8526 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8527 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8528 return E;
8529
8530 return getDerived().RebuildOMPArraySectionExpr(
8531 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8532 Length.get(), E->getRBracketLoc());
8533}
8534
Mike Stump11289f42009-09-09 15:08:12 +00008535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008537TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008539 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008540 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008541 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008542
8543 // Transform arguments.
8544 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008545 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008546 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008547 &ArgChanged))
8548 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008549
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 if (!getDerived().AlwaysRebuild() &&
8551 Callee.get() == E->getCallee() &&
8552 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008553 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008554
Douglas Gregora16548e2009-08-11 05:31:07 +00008555 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008556 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008558 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008559 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 E->getRParenLoc());
8561}
Mike Stump11289f42009-09-09 15:08:12 +00008562
8563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008565TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008566 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008569
Douglas Gregorea972d32011-02-28 21:54:11 +00008570 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008571 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008572 QualifierLoc
8573 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008574
Douglas Gregorea972d32011-02-28 21:54:11 +00008575 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008576 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008577 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008578 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008579
Eli Friedman2cfcef62009-12-04 06:40:45 +00008580 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008581 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8582 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008585
John McCall16df1e52010-03-30 21:47:33 +00008586 NamedDecl *FoundDecl = E->getFoundDecl();
8587 if (FoundDecl == E->getMemberDecl()) {
8588 FoundDecl = Member;
8589 } else {
8590 FoundDecl = cast_or_null<NamedDecl>(
8591 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8592 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008593 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008594 }
8595
Douglas Gregora16548e2009-08-11 05:31:07 +00008596 if (!getDerived().AlwaysRebuild() &&
8597 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008598 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008599 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008600 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008601 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008602
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008603 // Mark it referenced in the new context regardless.
8604 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008605 SemaRef.MarkMemberReferenced(E);
8606
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008607 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008608 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008609
John McCall6b51f282009-11-23 01:53:49 +00008610 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008611 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008612 TransArgs.setLAngleLoc(E->getLAngleLoc());
8613 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008614 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8615 E->getNumTemplateArgs(),
8616 TransArgs))
8617 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008619
Douglas Gregora16548e2009-08-11 05:31:07 +00008620 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008621 SourceLocation FakeOperatorLoc =
8622 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008623
John McCall38836f02010-01-15 08:34:02 +00008624 // FIXME: to do this check properly, we will need to preserve the
8625 // first-qualifier-in-scope here, just in case we had a dependent
8626 // base (and therefore couldn't do the check) and a
8627 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008628 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008629
John McCallb268a282010-08-23 23:25:46 +00008630 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008631 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008632 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008633 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008634 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008635 Member,
John McCall16df1e52010-03-30 21:47:33 +00008636 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008637 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008638 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008639 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008640}
Mike Stump11289f42009-09-09 15:08:12 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008644TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008645 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008648
John McCalldadc5752010-08-24 06:29:42 +00008649 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008652
Douglas Gregora16548e2009-08-11 05:31:07 +00008653 if (!getDerived().AlwaysRebuild() &&
8654 LHS.get() == E->getLHS() &&
8655 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008656 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008657
Lang Hames5de91cc2012-10-02 04:45:10 +00008658 Sema::FPContractStateRAII FPContractState(getSema());
8659 getSema().FPFeatures.fp_contract = E->isFPContractable();
8660
Douglas Gregora16548e2009-08-11 05:31:07 +00008661 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008662 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008663}
8664
Mike Stump11289f42009-09-09 15:08:12 +00008665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008666ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008667TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008668 CompoundAssignOperator *E) {
8669 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008670}
Mike Stump11289f42009-09-09 15:08:12 +00008671
Douglas Gregora16548e2009-08-11 05:31:07 +00008672template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008673ExprResult TreeTransform<Derived>::
8674TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8675 // Just rebuild the common and RHS expressions and see whether we
8676 // get any changes.
8677
8678 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8679 if (commonExpr.isInvalid())
8680 return ExprError();
8681
8682 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8683 if (rhs.isInvalid())
8684 return ExprError();
8685
8686 if (!getDerived().AlwaysRebuild() &&
8687 commonExpr.get() == e->getCommon() &&
8688 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008689 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008690
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008691 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008692 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008693 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008694 e->getColonLoc(),
8695 rhs.get());
8696}
8697
8698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008700TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008701 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008702 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008704
John McCalldadc5752010-08-24 06:29:42 +00008705 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008706 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008708
John McCalldadc5752010-08-24 06:29:42 +00008709 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008712
Douglas Gregora16548e2009-08-11 05:31:07 +00008713 if (!getDerived().AlwaysRebuild() &&
8714 Cond.get() == E->getCond() &&
8715 LHS.get() == E->getLHS() &&
8716 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008717 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008718
John McCallb268a282010-08-23 23:25:46 +00008719 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008720 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008721 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008722 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008723 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008724}
Mike Stump11289f42009-09-09 15:08:12 +00008725
8726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008727ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008728TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008729 // Implicit casts are eliminated during transformation, since they
8730 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008731 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008732}
Mike Stump11289f42009-09-09 15:08:12 +00008733
Douglas Gregora16548e2009-08-11 05:31:07 +00008734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008736TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008737 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8738 if (!Type)
8739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008740
John McCalldadc5752010-08-24 06:29:42 +00008741 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008742 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008745
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008747 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008749 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008750
John McCall97513962010-01-15 18:39:57 +00008751 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008752 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008753 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008754 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008755}
Mike Stump11289f42009-09-09 15:08:12 +00008756
Douglas Gregora16548e2009-08-11 05:31:07 +00008757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008758ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008759TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008760 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8761 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8762 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008764
John McCalldadc5752010-08-24 06:29:42 +00008765 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008766 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008768
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008770 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008771 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008772 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008773
John McCall5d7aa7f2010-01-19 22:33:45 +00008774 // Note: the expression type doesn't necessarily match the
8775 // type-as-written, but that's okay, because it should always be
8776 // derivable from the initializer.
8777
John McCalle15bbff2010-01-18 19:35:47 +00008778 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008779 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008780 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008781}
Mike Stump11289f42009-09-09 15:08:12 +00008782
Douglas Gregora16548e2009-08-11 05:31:07 +00008783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008786 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008787 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008789
Douglas Gregora16548e2009-08-11 05:31:07 +00008790 if (!getDerived().AlwaysRebuild() &&
8791 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008792 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008793
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008795 SourceLocation FakeOperatorLoc =
8796 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008797 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 E->getAccessorLoc(),
8799 E->getAccessor());
8800}
Mike Stump11289f42009-09-09 15:08:12 +00008801
Douglas Gregora16548e2009-08-11 05:31:07 +00008802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008804TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008805 if (InitListExpr *Syntactic = E->getSyntacticForm())
8806 E = Syntactic;
8807
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008809
Benjamin Kramerf0623432012-08-23 22:51:59 +00008810 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008811 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008812 Inits, &InitChanged))
8813 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008814
Richard Smith520449d2015-02-05 06:15:50 +00008815 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8816 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8817 // in some cases. We can't reuse it in general, because the syntactic and
8818 // semantic forms are linked, and we can't know that semantic form will
8819 // match even if the syntactic form does.
8820 }
Mike Stump11289f42009-09-09 15:08:12 +00008821
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008822 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008823 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008824}
Mike Stump11289f42009-09-09 15:08:12 +00008825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008828TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008829 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008830
Douglas Gregorebe10102009-08-20 07:17:43 +00008831 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008832 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008833 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008835
Douglas Gregorebe10102009-08-20 07:17:43 +00008836 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008837 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008838 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008839 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8840 if (D.isFieldDesignator()) {
8841 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8842 D.getDotLoc(),
8843 D.getFieldLoc()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 continue;
8845 }
Mike Stump11289f42009-09-09 15:08:12 +00008846
David Majnemerf7e36092016-06-23 00:15:04 +00008847 if (D.isArrayDesignator()) {
8848 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008851
David Majnemerf7e36092016-06-23 00:15:04 +00008852 Desig.AddDesignator(
8853 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008854
David Majnemerf7e36092016-06-23 00:15:04 +00008855 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008856 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008857 continue;
8858 }
Mike Stump11289f42009-09-09 15:08:12 +00008859
David Majnemerf7e36092016-06-23 00:15:04 +00008860 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008861 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00008862 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008863 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008865
David Majnemerf7e36092016-06-23 00:15:04 +00008866 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008867 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008869
8870 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008871 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00008872 D.getLBracketLoc(),
8873 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008874
David Majnemerf7e36092016-06-23 00:15:04 +00008875 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8876 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00008877
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008878 ArrayExprs.push_back(Start.get());
8879 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 }
Mike Stump11289f42009-09-09 15:08:12 +00008881
Douglas Gregora16548e2009-08-11 05:31:07 +00008882 if (!getDerived().AlwaysRebuild() &&
8883 Init.get() == E->getInit() &&
8884 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008885 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008886
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008887 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008888 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008889 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008890}
Mike Stump11289f42009-09-09 15:08:12 +00008891
Yunzhong Gaocb779302015-06-10 00:27:52 +00008892// Seems that if TransformInitListExpr() only works on the syntactic form of an
8893// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8894template<typename Derived>
8895ExprResult
8896TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8897 DesignatedInitUpdateExpr *E) {
8898 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8899 "initializer");
8900 return ExprError();
8901}
8902
8903template<typename Derived>
8904ExprResult
8905TreeTransform<Derived>::TransformNoInitExpr(
8906 NoInitExpr *E) {
8907 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8908 return ExprError();
8909}
8910
Douglas Gregora16548e2009-08-11 05:31:07 +00008911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008912ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008913TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008914 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008915 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008916
Douglas Gregor3da3c062009-10-28 00:29:27 +00008917 // FIXME: Will we ever have proper type location here? Will we actually
8918 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008919 QualType T = getDerived().TransformType(E->getType());
8920 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008922
Douglas Gregora16548e2009-08-11 05:31:07 +00008923 if (!getDerived().AlwaysRebuild() &&
8924 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008925 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008926
Douglas Gregora16548e2009-08-11 05:31:07 +00008927 return getDerived().RebuildImplicitValueInitExpr(T);
8928}
Mike Stump11289f42009-09-09 15:08:12 +00008929
Douglas Gregora16548e2009-08-11 05:31:07 +00008930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008932TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008933 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8934 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008935 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008936
John McCalldadc5752010-08-24 06:29:42 +00008937 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008938 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008940
Douglas Gregora16548e2009-08-11 05:31:07 +00008941 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008942 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008943 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008944 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008945
John McCallb268a282010-08-23 23:25:46 +00008946 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008947 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008948}
8949
8950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008952TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008953 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008954 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008955 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8956 &ArgumentChanged))
8957 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008958
Douglas Gregora16548e2009-08-11 05:31:07 +00008959 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008960 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008961 E->getRParenLoc());
8962}
Mike Stump11289f42009-09-09 15:08:12 +00008963
Douglas Gregora16548e2009-08-11 05:31:07 +00008964/// \brief Transform an address-of-label expression.
8965///
8966/// By default, the transformation of an address-of-label expression always
8967/// rebuilds the expression, so that the label identifier can be resolved to
8968/// the corresponding label statement by semantic analysis.
8969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008971TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008972 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8973 E->getLabel());
8974 if (!LD)
8975 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008976
Douglas Gregora16548e2009-08-11 05:31:07 +00008977 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008978 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008979}
Mike Stump11289f42009-09-09 15:08:12 +00008980
8981template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008982ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008983TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008984 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008985 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008987 if (SubStmt.isInvalid()) {
8988 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008989 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008990 }
Mike Stump11289f42009-09-09 15:08:12 +00008991
Douglas Gregora16548e2009-08-11 05:31:07 +00008992 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008993 SubStmt.get() == E->getSubStmt()) {
8994 // Calling this an 'error' is unintuitive, but it does the right thing.
8995 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008996 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008997 }
Mike Stump11289f42009-09-09 15:08:12 +00008998
8999 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009000 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009001 E->getRParenLoc());
9002}
Mike Stump11289f42009-09-09 15:08:12 +00009003
Douglas Gregora16548e2009-08-11 05:31:07 +00009004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009006TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009007 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009008 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009010
John McCalldadc5752010-08-24 06:29:42 +00009011 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009012 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009014
John McCalldadc5752010-08-24 06:29:42 +00009015 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009016 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009018
Douglas Gregora16548e2009-08-11 05:31:07 +00009019 if (!getDerived().AlwaysRebuild() &&
9020 Cond.get() == E->getCond() &&
9021 LHS.get() == E->getLHS() &&
9022 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009023 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009024
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009026 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009027 E->getRParenLoc());
9028}
Mike Stump11289f42009-09-09 15:08:12 +00009029
Douglas Gregora16548e2009-08-11 05:31:07 +00009030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009031ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009032TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009033 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009034}
9035
9036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009038TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009039 switch (E->getOperator()) {
9040 case OO_New:
9041 case OO_Delete:
9042 case OO_Array_New:
9043 case OO_Array_Delete:
9044 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009045
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009046 case OO_Call: {
9047 // This is a call to an object's operator().
9048 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9049
9050 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009051 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009052 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009053 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009054
9055 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009056 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9057 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009058
9059 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009060 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009061 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009062 Args))
9063 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009064
John McCallb268a282010-08-23 23:25:46 +00009065 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009066 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009067 E->getLocEnd());
9068 }
9069
9070#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9071 case OO_##Name:
9072#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9073#include "clang/Basic/OperatorKinds.def"
9074 case OO_Subscript:
9075 // Handled below.
9076 break;
9077
9078 case OO_Conditional:
9079 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009080
9081 case OO_None:
9082 case NUM_OVERLOADED_OPERATORS:
9083 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009084 }
9085
John McCalldadc5752010-08-24 06:29:42 +00009086 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009087 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009088 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009089
Richard Smithdb2630f2012-10-21 03:28:35 +00009090 ExprResult First;
9091 if (E->getOperator() == OO_Amp)
9092 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9093 else
9094 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009095 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009096 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009097
John McCalldadc5752010-08-24 06:29:42 +00009098 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009099 if (E->getNumArgs() == 2) {
9100 Second = getDerived().TransformExpr(E->getArg(1));
9101 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009102 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009103 }
Mike Stump11289f42009-09-09 15:08:12 +00009104
Douglas Gregora16548e2009-08-11 05:31:07 +00009105 if (!getDerived().AlwaysRebuild() &&
9106 Callee.get() == E->getCallee() &&
9107 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009108 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009109 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009110
Lang Hames5de91cc2012-10-02 04:45:10 +00009111 Sema::FPContractStateRAII FPContractState(getSema());
9112 getSema().FPFeatures.fp_contract = E->isFPContractable();
9113
Douglas Gregora16548e2009-08-11 05:31:07 +00009114 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9115 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009116 Callee.get(),
9117 First.get(),
9118 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009119}
Mike Stump11289f42009-09-09 15:08:12 +00009120
Douglas Gregora16548e2009-08-11 05:31:07 +00009121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009123TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9124 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009125}
Mike Stump11289f42009-09-09 15:08:12 +00009126
Douglas Gregora16548e2009-08-11 05:31:07 +00009127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009128ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009129TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9130 // Transform the callee.
9131 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9132 if (Callee.isInvalid())
9133 return ExprError();
9134
9135 // Transform exec config.
9136 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9137 if (EC.isInvalid())
9138 return ExprError();
9139
9140 // Transform arguments.
9141 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009142 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009143 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009144 &ArgChanged))
9145 return ExprError();
9146
9147 if (!getDerived().AlwaysRebuild() &&
9148 Callee.get() == E->getCallee() &&
9149 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009150 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009151
9152 // FIXME: Wrong source location information for the '('.
9153 SourceLocation FakeLParenLoc
9154 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9155 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009156 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009157 E->getRParenLoc(), EC.get());
9158}
9159
9160template<typename Derived>
9161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009162TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009163 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9164 if (!Type)
9165 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009166
John McCalldadc5752010-08-24 06:29:42 +00009167 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009168 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009171
Douglas Gregora16548e2009-08-11 05:31:07 +00009172 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009173 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009174 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009175 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009176 return getDerived().RebuildCXXNamedCastExpr(
9177 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9178 Type, E->getAngleBrackets().getEnd(),
9179 // FIXME. this should be '(' location
9180 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009181}
Mike Stump11289f42009-09-09 15:08:12 +00009182
Douglas Gregora16548e2009-08-11 05:31:07 +00009183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009185TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9186 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009187}
Mike Stump11289f42009-09-09 15:08:12 +00009188
9189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009191TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9192 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009193}
9194
Douglas Gregora16548e2009-08-11 05:31:07 +00009195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009196ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009197TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009198 CXXReinterpretCastExpr *E) {
9199 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009200}
Mike Stump11289f42009-09-09 15:08:12 +00009201
Douglas Gregora16548e2009-08-11 05:31:07 +00009202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009204TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9205 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009206}
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregora16548e2009-08-11 05:31:07 +00009208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009209ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009210TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009211 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009212 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9213 if (!Type)
9214 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009215
John McCalldadc5752010-08-24 06:29:42 +00009216 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009217 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009218 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009220
Douglas Gregora16548e2009-08-11 05:31:07 +00009221 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009222 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009223 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009225
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009226 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009227 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009228 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009229 E->getRParenLoc());
9230}
Mike Stump11289f42009-09-09 15:08:12 +00009231
Douglas Gregora16548e2009-08-11 05:31:07 +00009232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009234TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009235 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009236 TypeSourceInfo *TInfo
9237 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9238 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009240
Douglas Gregora16548e2009-08-11 05:31:07 +00009241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009242 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009243 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009244
Douglas Gregor9da64192010-04-26 22:37:10 +00009245 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9246 E->getLocStart(),
9247 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009248 E->getLocEnd());
9249 }
Mike Stump11289f42009-09-09 15:08:12 +00009250
Eli Friedman456f0182012-01-20 01:26:23 +00009251 // We don't know whether the subexpression is potentially evaluated until
9252 // after we perform semantic analysis. We speculatively assume it is
9253 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009254 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009255 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9256 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009257
John McCalldadc5752010-08-24 06:29:42 +00009258 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009259 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009261
Douglas Gregora16548e2009-08-11 05:31:07 +00009262 if (!getDerived().AlwaysRebuild() &&
9263 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009264 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregor9da64192010-04-26 22:37:10 +00009266 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9267 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009268 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 E->getLocEnd());
9270}
9271
9272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009273ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009274TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9275 if (E->isTypeOperand()) {
9276 TypeSourceInfo *TInfo
9277 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9278 if (!TInfo)
9279 return ExprError();
9280
9281 if (!getDerived().AlwaysRebuild() &&
9282 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009283 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009284
Douglas Gregor69735112011-03-06 17:40:41 +00009285 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009286 E->getLocStart(),
9287 TInfo,
9288 E->getLocEnd());
9289 }
9290
Francois Pichet9f4f2072010-09-08 12:20:18 +00009291 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9292
9293 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9294 if (SubExpr.isInvalid())
9295 return ExprError();
9296
9297 if (!getDerived().AlwaysRebuild() &&
9298 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009299 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009300
9301 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9302 E->getLocStart(),
9303 SubExpr.get(),
9304 E->getLocEnd());
9305}
9306
9307template<typename Derived>
9308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009309TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009310 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009311}
Mike Stump11289f42009-09-09 15:08:12 +00009312
Douglas Gregora16548e2009-08-11 05:31:07 +00009313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009314ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009315TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009316 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009317 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009318}
Mike Stump11289f42009-09-09 15:08:12 +00009319
Douglas Gregora16548e2009-08-11 05:31:07 +00009320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009322TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009323 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009324
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009325 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9326 // Make sure that we capture 'this'.
9327 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009328 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009330
Douglas Gregorb15af892010-01-07 23:12:05 +00009331 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009332}
Mike Stump11289f42009-09-09 15:08:12 +00009333
Douglas Gregora16548e2009-08-11 05:31:07 +00009334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009336TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009337 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009338 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 if (!getDerived().AlwaysRebuild() &&
9342 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009343 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009344
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009345 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9346 E->isThrownVariableInScope());
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
John McCall47f29ea2009-12-08 09:21:05 +00009351TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009352 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009353 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9354 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009355 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009357
Chandler Carruth794da4c2010-02-08 06:42:49 +00009358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009359 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009360 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009361
Douglas Gregor033f6752009-12-23 23:03:06 +00009362 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009363}
Mike Stump11289f42009-09-09 15:08:12 +00009364
Douglas Gregora16548e2009-08-11 05:31:07 +00009365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009366ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009367TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9368 FieldDecl *Field
9369 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9370 E->getField()));
9371 if (!Field)
9372 return ExprError();
9373
9374 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009375 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009376
9377 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9378}
9379
9380template<typename Derived>
9381ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009382TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9383 CXXScalarValueInitExpr *E) {
9384 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9385 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009386 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009387
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009389 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009390 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009391
Chad Rosier1dcde962012-08-08 18:46:20 +00009392 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009393 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009394 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009395}
Mike Stump11289f42009-09-09 15:08:12 +00009396
Douglas Gregora16548e2009-08-11 05:31:07 +00009397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009398ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009399TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009400 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009401 TypeSourceInfo *AllocTypeInfo
9402 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9403 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009405
Douglas Gregora16548e2009-08-11 05:31:07 +00009406 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009407 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009408 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009410
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 // Transform the placement arguments (if any).
9412 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009413 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009414 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009415 E->getNumPlacementArgs(), true,
9416 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009418
Sebastian Redl6047f072012-02-16 12:22:20 +00009419 // Transform the initializer (if any).
9420 Expr *OldInit = E->getInitializer();
9421 ExprResult NewInit;
9422 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009423 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009424 if (NewInit.isInvalid())
9425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009426
Sebastian Redl6047f072012-02-16 12:22:20 +00009427 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009428 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009429 if (E->getOperatorNew()) {
9430 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009431 getDerived().TransformDecl(E->getLocStart(),
9432 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009433 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009434 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009435 }
9436
Craig Topperc3ec1492014-05-26 06:22:03 +00009437 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009438 if (E->getOperatorDelete()) {
9439 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009440 getDerived().TransformDecl(E->getLocStart(),
9441 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009442 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009443 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009444 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009445
Douglas Gregora16548e2009-08-11 05:31:07 +00009446 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009447 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009448 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009449 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009450 OperatorNew == E->getOperatorNew() &&
9451 OperatorDelete == E->getOperatorDelete() &&
9452 !ArgumentChanged) {
9453 // Mark any declarations we need as referenced.
9454 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009455 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009456 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009457 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009458 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009459
Sebastian Redl6047f072012-02-16 12:22:20 +00009460 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009461 QualType ElementType
9462 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9463 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9464 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9465 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009466 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009467 }
9468 }
9469 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009470
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009471 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009472 }
Mike Stump11289f42009-09-09 15:08:12 +00009473
Douglas Gregor0744ef62010-09-07 21:49:58 +00009474 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009475 if (!ArraySize.get()) {
9476 // If no array size was specified, but the new expression was
9477 // instantiated with an array type (e.g., "new T" where T is
9478 // instantiated with "int[4]"), extract the outer bound from the
9479 // array type as our array size. We do this with constant and
9480 // dependently-sized array types.
9481 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9482 if (!ArrayT) {
9483 // Do nothing
9484 } else if (const ConstantArrayType *ConsArrayT
9485 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009486 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9487 SemaRef.Context.getSizeType(),
9488 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009489 AllocType = ConsArrayT->getElementType();
9490 } else if (const DependentSizedArrayType *DepArrayT
9491 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9492 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009493 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009494 AllocType = DepArrayT->getElementType();
9495 }
9496 }
9497 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9500 E->isGlobalNew(),
9501 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009502 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009504 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009505 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009506 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009507 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009508 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009509 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009510}
Mike Stump11289f42009-09-09 15:08:12 +00009511
Douglas Gregora16548e2009-08-11 05:31:07 +00009512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009513ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009514TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009515 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009516 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009518
Douglas Gregord2d9da02010-02-26 00:38:10 +00009519 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009520 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009521 if (E->getOperatorDelete()) {
9522 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009523 getDerived().TransformDecl(E->getLocStart(),
9524 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009525 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009526 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009528
Douglas Gregora16548e2009-08-11 05:31:07 +00009529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009530 Operand.get() == E->getArgument() &&
9531 OperatorDelete == E->getOperatorDelete()) {
9532 // Mark any declarations we need as referenced.
9533 // FIXME: instantiation-specific.
9534 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009535 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009536
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009537 if (!E->getArgument()->isTypeDependent()) {
9538 QualType Destroyed = SemaRef.Context.getBaseElementType(
9539 E->getDestroyedType());
9540 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9541 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009542 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009543 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009544 }
9545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009546
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009547 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009548 }
Mike Stump11289f42009-09-09 15:08:12 +00009549
Douglas Gregora16548e2009-08-11 05:31:07 +00009550 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9551 E->isGlobalDelete(),
9552 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009553 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009554}
Mike Stump11289f42009-09-09 15:08:12 +00009555
Douglas Gregora16548e2009-08-11 05:31:07 +00009556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009557ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009558TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009559 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009560 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009561 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009563
John McCallba7bf592010-08-24 05:47:05 +00009564 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009565 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009566 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009567 E->getOperatorLoc(),
9568 E->isArrow()? tok::arrow : tok::period,
9569 ObjectTypePtr,
9570 MayBePseudoDestructor);
9571 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009572 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009573
John McCallba7bf592010-08-24 05:47:05 +00009574 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009575 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9576 if (QualifierLoc) {
9577 QualifierLoc
9578 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9579 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009580 return ExprError();
9581 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009582 CXXScopeSpec SS;
9583 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009584
Douglas Gregor678f90d2010-02-25 01:56:36 +00009585 PseudoDestructorTypeStorage Destroyed;
9586 if (E->getDestroyedTypeInfo()) {
9587 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009588 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009589 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009590 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009591 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009592 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009593 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009594 // We aren't likely to be able to resolve the identifier down to a type
9595 // now anyway, so just retain the identifier.
9596 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9597 E->getDestroyedTypeLoc());
9598 } else {
9599 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009600 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009601 *E->getDestroyedTypeIdentifier(),
9602 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009603 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009604 SS, ObjectTypePtr,
9605 false);
9606 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009607 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009608
Douglas Gregor678f90d2010-02-25 01:56:36 +00009609 Destroyed
9610 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9611 E->getDestroyedTypeLoc());
9612 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009613
Craig Topperc3ec1492014-05-26 06:22:03 +00009614 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009615 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009616 CXXScopeSpec EmptySS;
9617 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009618 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009619 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009620 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009622
John McCallb268a282010-08-23 23:25:46 +00009623 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009624 E->getOperatorLoc(),
9625 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009626 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009627 ScopeTypeInfo,
9628 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009629 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009630 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009631}
Mike Stump11289f42009-09-09 15:08:12 +00009632
Douglas Gregorad8a3362009-09-04 17:36:40 +00009633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009634ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009635TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009636 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009637 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9638 Sema::LookupOrdinaryName);
9639
9640 // Transform all the decls.
9641 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9642 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009643 NamedDecl *InstD = static_cast<NamedDecl*>(
9644 getDerived().TransformDecl(Old->getNameLoc(),
9645 *I));
John McCall84d87672009-12-10 09:41:52 +00009646 if (!InstD) {
9647 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9648 // This can happen because of dependent hiding.
9649 if (isa<UsingShadowDecl>(*I))
9650 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009651 else {
9652 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009653 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009654 }
John McCall84d87672009-12-10 09:41:52 +00009655 }
John McCalle66edc12009-11-24 19:00:30 +00009656
9657 // Expand using declarations.
9658 if (isa<UsingDecl>(InstD)) {
9659 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009660 for (auto *I : UD->shadows())
9661 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009662 continue;
9663 }
9664
9665 R.addDecl(InstD);
9666 }
9667
9668 // Resolve a kind, but don't do any further analysis. If it's
9669 // ambiguous, the callee needs to deal with it.
9670 R.resolveKind();
9671
9672 // Rebuild the nested-name qualifier, if present.
9673 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009674 if (Old->getQualifierLoc()) {
9675 NestedNameSpecifierLoc QualifierLoc
9676 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9677 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009678 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009679
Douglas Gregor0da1d432011-02-28 20:01:57 +00009680 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009681 }
9682
Douglas Gregor9262f472010-04-27 18:19:34 +00009683 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009684 CXXRecordDecl *NamingClass
9685 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9686 Old->getNameLoc(),
9687 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009688 if (!NamingClass) {
9689 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009690 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009692
Douglas Gregorda7be082010-04-27 16:10:10 +00009693 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009694 }
9695
Abramo Bagnara7945c982012-01-27 09:46:47 +00009696 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9697
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009698 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009699 // it's a normal declaration name or member reference.
9700 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9701 NamedDecl *D = R.getAsSingle<NamedDecl>();
9702 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9703 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9704 // give a good diagnostic.
9705 if (D && D->isCXXInstanceMember()) {
9706 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9707 /*TemplateArgs=*/nullptr,
9708 /*Scope=*/nullptr);
9709 }
9710
John McCalle66edc12009-11-24 19:00:30 +00009711 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009712 }
John McCalle66edc12009-11-24 19:00:30 +00009713
9714 // If we have template arguments, rebuild them, then rebuild the
9715 // templateid expression.
9716 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009717 if (Old->hasExplicitTemplateArgs() &&
9718 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009719 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009720 TransArgs)) {
9721 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009722 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009723 }
John McCalle66edc12009-11-24 19:00:30 +00009724
Abramo Bagnara7945c982012-01-27 09:46:47 +00009725 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009726 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009727}
Mike Stump11289f42009-09-09 15:08:12 +00009728
Douglas Gregora16548e2009-08-11 05:31:07 +00009729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009730ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009731TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9732 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009733 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009734 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9735 TypeSourceInfo *From = E->getArg(I);
9736 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009737 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009738 TypeLocBuilder TLB;
9739 TLB.reserve(FromTL.getFullDataSize());
9740 QualType To = getDerived().TransformType(TLB, FromTL);
9741 if (To.isNull())
9742 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009743
Douglas Gregor29c42f22012-02-24 07:38:34 +00009744 if (To == From->getType())
9745 Args.push_back(From);
9746 else {
9747 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9748 ArgChanged = true;
9749 }
9750 continue;
9751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009752
Douglas Gregor29c42f22012-02-24 07:38:34 +00009753 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009754
Douglas Gregor29c42f22012-02-24 07:38:34 +00009755 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009756 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009757 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9758 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9759 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009760
Douglas Gregor29c42f22012-02-24 07:38:34 +00009761 // Determine whether the set of unexpanded parameter packs can and should
9762 // be expanded.
9763 bool Expand = true;
9764 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009765 Optional<unsigned> OrigNumExpansions =
9766 ExpansionTL.getTypePtr()->getNumExpansions();
9767 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009768 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9769 PatternTL.getSourceRange(),
9770 Unexpanded,
9771 Expand, RetainExpansion,
9772 NumExpansions))
9773 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009774
Douglas Gregor29c42f22012-02-24 07:38:34 +00009775 if (!Expand) {
9776 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009777 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009778 // expansion.
9779 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009780
Douglas Gregor29c42f22012-02-24 07:38:34 +00009781 TypeLocBuilder TLB;
9782 TLB.reserve(From->getTypeLoc().getFullDataSize());
9783
9784 QualType To = getDerived().TransformType(TLB, PatternTL);
9785 if (To.isNull())
9786 return ExprError();
9787
Chad Rosier1dcde962012-08-08 18:46:20 +00009788 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009789 PatternTL.getSourceRange(),
9790 ExpansionTL.getEllipsisLoc(),
9791 NumExpansions);
9792 if (To.isNull())
9793 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009794
Douglas Gregor29c42f22012-02-24 07:38:34 +00009795 PackExpansionTypeLoc ToExpansionTL
9796 = TLB.push<PackExpansionTypeLoc>(To);
9797 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9798 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9799 continue;
9800 }
9801
9802 // Expand the pack expansion by substituting for each argument in the
9803 // pack(s).
9804 for (unsigned I = 0; I != *NumExpansions; ++I) {
9805 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9806 TypeLocBuilder TLB;
9807 TLB.reserve(PatternTL.getFullDataSize());
9808 QualType To = getDerived().TransformType(TLB, PatternTL);
9809 if (To.isNull())
9810 return ExprError();
9811
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009812 if (To->containsUnexpandedParameterPack()) {
9813 To = getDerived().RebuildPackExpansionType(To,
9814 PatternTL.getSourceRange(),
9815 ExpansionTL.getEllipsisLoc(),
9816 NumExpansions);
9817 if (To.isNull())
9818 return ExprError();
9819
9820 PackExpansionTypeLoc ToExpansionTL
9821 = TLB.push<PackExpansionTypeLoc>(To);
9822 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9823 }
9824
Douglas Gregor29c42f22012-02-24 07:38:34 +00009825 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009827
Douglas Gregor29c42f22012-02-24 07:38:34 +00009828 if (!RetainExpansion)
9829 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009830
Douglas Gregor29c42f22012-02-24 07:38:34 +00009831 // If we're supposed to retain a pack expansion, do so by temporarily
9832 // forgetting the partially-substituted parameter pack.
9833 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9834
9835 TypeLocBuilder TLB;
9836 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009837
Douglas Gregor29c42f22012-02-24 07:38:34 +00009838 QualType To = getDerived().TransformType(TLB, PatternTL);
9839 if (To.isNull())
9840 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009841
9842 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009843 PatternTL.getSourceRange(),
9844 ExpansionTL.getEllipsisLoc(),
9845 NumExpansions);
9846 if (To.isNull())
9847 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009848
Douglas Gregor29c42f22012-02-24 07:38:34 +00009849 PackExpansionTypeLoc ToExpansionTL
9850 = TLB.push<PackExpansionTypeLoc>(To);
9851 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9852 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009854
Douglas Gregor29c42f22012-02-24 07:38:34 +00009855 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009856 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009857
9858 return getDerived().RebuildTypeTrait(E->getTrait(),
9859 E->getLocStart(),
9860 Args,
9861 E->getLocEnd());
9862}
9863
9864template<typename Derived>
9865ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009866TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9867 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9868 if (!T)
9869 return ExprError();
9870
9871 if (!getDerived().AlwaysRebuild() &&
9872 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009873 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009874
9875 ExprResult SubExpr;
9876 {
9877 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9878 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9879 if (SubExpr.isInvalid())
9880 return ExprError();
9881
9882 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009883 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009884 }
9885
9886 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9887 E->getLocStart(),
9888 T,
9889 SubExpr.get(),
9890 E->getLocEnd());
9891}
9892
9893template<typename Derived>
9894ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009895TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9896 ExprResult SubExpr;
9897 {
9898 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9899 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9900 if (SubExpr.isInvalid())
9901 return ExprError();
9902
9903 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009904 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009905 }
9906
9907 return getDerived().RebuildExpressionTrait(
9908 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9909}
9910
Reid Kleckner32506ed2014-06-12 23:03:48 +00009911template <typename Derived>
9912ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9913 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9914 TypeSourceInfo **RecoveryTSI) {
9915 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9916 DRE, AddrTaken, RecoveryTSI);
9917
9918 // Propagate both errors and recovered types, which return ExprEmpty.
9919 if (!NewDRE.isUsable())
9920 return NewDRE;
9921
9922 // We got an expr, wrap it up in parens.
9923 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9924 return PE;
9925 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9926 PE->getRParen());
9927}
9928
9929template <typename Derived>
9930ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9931 DependentScopeDeclRefExpr *E) {
9932 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9933 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009934}
9935
9936template<typename Derived>
9937ExprResult
9938TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9939 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009940 bool IsAddressOfOperand,
9941 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009942 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009943 NestedNameSpecifierLoc QualifierLoc
9944 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9945 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009946 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009947 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009948
John McCall31f82722010-11-12 08:19:04 +00009949 // TODO: If this is a conversion-function-id, verify that the
9950 // destination type name (if present) resolves the same way after
9951 // instantiation as it did in the local scope.
9952
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009953 DeclarationNameInfo NameInfo
9954 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9955 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009957
John McCalle66edc12009-11-24 19:00:30 +00009958 if (!E->hasExplicitTemplateArgs()) {
9959 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009960 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009961 // Note: it is sufficient to compare the Name component of NameInfo:
9962 // if name has not changed, DNLoc has not changed either.
9963 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009964 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009965
Reid Kleckner32506ed2014-06-12 23:03:48 +00009966 return getDerived().RebuildDependentScopeDeclRefExpr(
9967 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9968 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009969 }
John McCall6b51f282009-11-23 01:53:49 +00009970
9971 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009972 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9973 E->getNumTemplateArgs(),
9974 TransArgs))
9975 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009976
Reid Kleckner32506ed2014-06-12 23:03:48 +00009977 return getDerived().RebuildDependentScopeDeclRefExpr(
9978 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9979 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009980}
9981
9982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009984TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009985 // CXXConstructExprs other than for list-initialization and
9986 // CXXTemporaryObjectExpr are always implicit, so when we have
9987 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009988 if ((E->getNumArgs() == 1 ||
9989 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009990 (!getDerived().DropCallArgument(E->getArg(0))) &&
9991 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009992 return getDerived().TransformExpr(E->getArg(0));
9993
Douglas Gregora16548e2009-08-11 05:31:07 +00009994 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9995
9996 QualType T = getDerived().TransformType(E->getType());
9997 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009998 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009999
10000 CXXConstructorDecl *Constructor
10001 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010002 getDerived().TransformDecl(E->getLocStart(),
10003 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010004 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010006
Douglas Gregora16548e2009-08-11 05:31:07 +000010007 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010008 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010009 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010010 &ArgumentChanged))
10011 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010012
Douglas Gregora16548e2009-08-11 05:31:07 +000010013 if (!getDerived().AlwaysRebuild() &&
10014 T == E->getType() &&
10015 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010016 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010017 // Mark the constructor as referenced.
10018 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010019 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010020 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010021 }
Mike Stump11289f42009-09-09 15:08:12 +000010022
Douglas Gregordb121ba2009-12-14 16:27:04 +000010023 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010024 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010025 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010026 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010027 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010028 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010029 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010030 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010031 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010032}
Mike Stump11289f42009-09-09 15:08:12 +000010033
Richard Smith5179eb72016-06-28 19:03:57 +000010034template<typename Derived>
10035ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10036 CXXInheritedCtorInitExpr *E) {
10037 QualType T = getDerived().TransformType(E->getType());
10038 if (T.isNull())
10039 return ExprError();
10040
10041 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10042 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10043 if (!Constructor)
10044 return ExprError();
10045
10046 if (!getDerived().AlwaysRebuild() &&
10047 T == E->getType() &&
10048 Constructor == E->getConstructor()) {
10049 // Mark the constructor as referenced.
10050 // FIXME: Instantiation-specific
10051 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10052 return E;
10053 }
10054
10055 return getDerived().RebuildCXXInheritedCtorInitExpr(
10056 T, E->getLocation(), Constructor,
10057 E->constructsVBase(), E->inheritedFromVBase());
10058}
10059
Douglas Gregora16548e2009-08-11 05:31:07 +000010060/// \brief Transform a C++ temporary-binding expression.
10061///
Douglas Gregor363b1512009-12-24 18:51:59 +000010062/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10063/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010066TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010067 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010068}
Mike Stump11289f42009-09-09 15:08:12 +000010069
John McCall5d413782010-12-06 08:20:24 +000010070/// \brief Transform a C++ expression that contains cleanups that should
10071/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010072///
John McCall5d413782010-12-06 08:20:24 +000010073/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010074/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010076ExprResult
John McCall5d413782010-12-06 08:20:24 +000010077TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010078 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010079}
Mike Stump11289f42009-09-09 15:08:12 +000010080
Douglas Gregora16548e2009-08-11 05:31:07 +000010081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010082ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010083TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010084 CXXTemporaryObjectExpr *E) {
10085 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10086 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010088
Douglas Gregora16548e2009-08-11 05:31:07 +000010089 CXXConstructorDecl *Constructor
10090 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010091 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010092 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010093 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010095
Douglas Gregora16548e2009-08-11 05:31:07 +000010096 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010097 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010098 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010099 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010100 &ArgumentChanged))
10101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010102
Douglas Gregora16548e2009-08-11 05:31:07 +000010103 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010104 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010105 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010106 !ArgumentChanged) {
10107 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010108 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010109 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010110 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010111
Richard Smithd59b8322012-12-19 01:39:02 +000010112 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010113 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10114 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010115 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010116 E->getLocEnd());
10117}
Mike Stump11289f42009-09-09 15:08:12 +000010118
Douglas Gregora16548e2009-08-11 05:31:07 +000010119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010120ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010121TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010122 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010123 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010124 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010125 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10126 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010127 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010128 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010129 CEnd = E->capture_end();
10130 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010131 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010132 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010133 EnterExpressionEvaluationContext EEEC(getSema(),
10134 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010135 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10136 C->getCapturedVar()->getInit(),
10137 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010138
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010139 if (NewExprInitResult.isInvalid())
10140 return ExprError();
10141 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010142
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010143 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010144 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010145 getSema().buildLambdaInitCaptureInitialization(
10146 C->getLocation(), OldVD->getType()->isReferenceType(),
10147 OldVD->getIdentifier(),
10148 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010149 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010150 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10151 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010152 }
10153
Faisal Vali2cba1332013-10-23 06:44:28 +000010154 // Transform the template parameters, and add them to the current
10155 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010156 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010157 E->getTemplateParameterList());
10158
Richard Smith01014ce2014-11-20 23:53:14 +000010159 // Transform the type of the original lambda's call operator.
10160 // The transformation MUST be done in the CurrentInstantiationScope since
10161 // it introduces a mapping of the original to the newly created
10162 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010163 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010164 {
10165 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10166 FunctionProtoTypeLoc OldCallOpFPTL =
10167 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010168
10169 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010170 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010171 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010172 QualType NewCallOpType = TransformFunctionProtoType(
10173 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010174 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10175 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10176 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010177 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010178 if (NewCallOpType.isNull())
10179 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010180 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10181 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010182 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010183
Richard Smithc38498f2015-04-27 21:27:54 +000010184 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10185 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10186 LSI->GLTemplateParameterList = TPL;
10187
Eli Friedmand564afb2012-09-19 01:18:11 +000010188 // Create the local class that will describe the lambda.
10189 CXXRecordDecl *Class
10190 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010191 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010192 /*KnownDependent=*/false,
10193 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010194 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10195
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010196 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010197 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10198 Class, E->getIntroducerRange(), NewCallOpTSI,
10199 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010200 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10201 E->getCallOperator()->isConstexpr());
10202
Faisal Vali2cba1332013-10-23 06:44:28 +000010203 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010204
Faisal Vali2cba1332013-10-23 06:44:28 +000010205 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010206 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010207
Douglas Gregorb4328232012-02-14 00:00:48 +000010208 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010209 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010210 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010211
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010212 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010213 getSema().buildLambdaScope(LSI, NewCallOperator,
10214 E->getIntroducerRange(),
10215 E->getCaptureDefault(),
10216 E->getCaptureDefaultLoc(),
10217 E->hasExplicitParameters(),
10218 E->hasExplicitResultType(),
10219 E->isMutable());
10220
10221 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010222
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010223 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010224 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010225 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010226 CEnd = E->capture_end();
10227 C != CEnd; ++C) {
10228 // When we hit the first implicit capture, tell Sema that we've finished
10229 // the list of explicit captures.
10230 if (!FinishedExplicitCaptures && C->isImplicit()) {
10231 getSema().finishLambdaExplicitCaptures(LSI);
10232 FinishedExplicitCaptures = true;
10233 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010234
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010235 // Capturing 'this' is trivial.
10236 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010237 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10238 /*BuildAndDiagnose*/ true, nullptr,
10239 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010240 continue;
10241 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010242 // Captured expression will be recaptured during captured variables
10243 // rebuilding.
10244 if (C->capturesVLAType())
10245 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010246
Richard Smithba71c082013-05-16 06:20:58 +000010247 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010248 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010249 InitCaptureInfoTy InitExprTypePair =
10250 InitCaptureExprsAndTypes[C - E->capture_begin()];
10251 ExprResult Init = InitExprTypePair.first;
10252 QualType InitQualType = InitExprTypePair.second;
10253 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010254 Invalid = true;
10255 continue;
10256 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010257 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010258 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010259 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10260 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010261 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010262 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010263 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010264 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010265 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010266 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010267 continue;
10268 }
10269
10270 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10271
Douglas Gregor3e308b12012-02-14 19:27:52 +000010272 // Determine the capture kind for Sema.
10273 Sema::TryCaptureKind Kind
10274 = C->isImplicit()? Sema::TryCapture_Implicit
10275 : C->getCaptureKind() == LCK_ByCopy
10276 ? Sema::TryCapture_ExplicitByVal
10277 : Sema::TryCapture_ExplicitByRef;
10278 SourceLocation EllipsisLoc;
10279 if (C->isPackExpansion()) {
10280 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10281 bool ShouldExpand = false;
10282 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010283 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010284 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10285 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010286 Unexpanded,
10287 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010288 NumExpansions)) {
10289 Invalid = true;
10290 continue;
10291 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010292
Douglas Gregor3e308b12012-02-14 19:27:52 +000010293 if (ShouldExpand) {
10294 // The transform has determined that we should perform an expansion;
10295 // transform and capture each of the arguments.
10296 // expansion of the pattern. Do so.
10297 VarDecl *Pack = C->getCapturedVar();
10298 for (unsigned I = 0; I != *NumExpansions; ++I) {
10299 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10300 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010301 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010302 Pack));
10303 if (!CapturedVar) {
10304 Invalid = true;
10305 continue;
10306 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010307
Douglas Gregor3e308b12012-02-14 19:27:52 +000010308 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010309 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10310 }
Richard Smith9467be42014-06-06 17:33:35 +000010311
10312 // FIXME: Retain a pack expansion if RetainExpansion is true.
10313
Douglas Gregor3e308b12012-02-14 19:27:52 +000010314 continue;
10315 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010316
Douglas Gregor3e308b12012-02-14 19:27:52 +000010317 EllipsisLoc = C->getEllipsisLoc();
10318 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010319
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010320 // Transform the captured variable.
10321 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010322 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010323 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010324 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010325 Invalid = true;
10326 continue;
10327 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010328
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010329 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010330 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10331 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010332 }
10333 if (!FinishedExplicitCaptures)
10334 getSema().finishLambdaExplicitCaptures(LSI);
10335
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010336 // Enter a new evaluation context to insulate the lambda from any
10337 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010338 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010339
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010340 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010341 StmtResult Body =
10342 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10343
10344 // ActOnLambda* will pop the function scope for us.
10345 FuncScopeCleanup.disable();
10346
Douglas Gregorb4328232012-02-14 00:00:48 +000010347 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010348 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010349 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010350 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010351 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010352 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010353
Richard Smithc38498f2015-04-27 21:27:54 +000010354 // Copy the LSI before ActOnFinishFunctionBody removes it.
10355 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10356 // the call operator.
10357 auto LSICopy = *LSI;
10358 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10359 /*IsInstantiation*/ true);
10360 SavedContext.pop();
10361
10362 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10363 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010364}
10365
10366template<typename Derived>
10367ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010368TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010369 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010370 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10371 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010373
Douglas Gregora16548e2009-08-11 05:31:07 +000010374 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010375 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010376 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010377 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010378 &ArgumentChanged))
10379 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010380
Douglas Gregora16548e2009-08-11 05:31:07 +000010381 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010382 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010383 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010384 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010385
Douglas Gregora16548e2009-08-11 05:31:07 +000010386 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010387 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010388 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010389 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010390 E->getRParenLoc());
10391}
Mike Stump11289f42009-09-09 15:08:12 +000010392
Douglas Gregora16548e2009-08-11 05:31:07 +000010393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010394ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010395TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010396 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010397 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010398 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010399 Expr *OldBase;
10400 QualType BaseType;
10401 QualType ObjectType;
10402 if (!E->isImplicitAccess()) {
10403 OldBase = E->getBase();
10404 Base = getDerived().TransformExpr(OldBase);
10405 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010407
John McCall2d74de92009-12-01 22:10:20 +000010408 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010409 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010410 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010411 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010412 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010413 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010414 ObjectTy,
10415 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010416 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010417 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010418
John McCallba7bf592010-08-24 05:47:05 +000010419 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010420 BaseType = ((Expr*) Base.get())->getType();
10421 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010422 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010423 BaseType = getDerived().TransformType(E->getBaseType());
10424 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10425 }
Mike Stump11289f42009-09-09 15:08:12 +000010426
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010427 // Transform the first part of the nested-name-specifier that qualifies
10428 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010429 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010430 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010431 E->getFirstQualifierFoundInScope(),
10432 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010433
Douglas Gregore16af532011-02-28 18:50:33 +000010434 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010435 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010436 QualifierLoc
10437 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10438 ObjectType,
10439 FirstQualifierInScope);
10440 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010441 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010442 }
Mike Stump11289f42009-09-09 15:08:12 +000010443
Abramo Bagnara7945c982012-01-27 09:46:47 +000010444 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10445
John McCall31f82722010-11-12 08:19:04 +000010446 // TODO: If this is a conversion-function-id, verify that the
10447 // destination type name (if present) resolves the same way after
10448 // instantiation as it did in the local scope.
10449
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010450 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010451 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010452 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010454
John McCall2d74de92009-12-01 22:10:20 +000010455 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010456 // This is a reference to a member without an explicitly-specified
10457 // template argument list. Optimize for this common case.
10458 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010459 Base.get() == OldBase &&
10460 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010461 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010462 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010463 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010464 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010465
John McCallb268a282010-08-23 23:25:46 +000010466 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010467 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010468 E->isArrow(),
10469 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010470 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010471 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010472 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010473 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010474 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010475 }
10476
John McCall6b51f282009-11-23 01:53:49 +000010477 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010478 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10479 E->getNumTemplateArgs(),
10480 TransArgs))
10481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010482
John McCallb268a282010-08-23 23:25:46 +000010483 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010484 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010485 E->isArrow(),
10486 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010487 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010488 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010489 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010490 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010491 &TransArgs);
10492}
10493
10494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010496TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010497 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010498 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010499 QualType BaseType;
10500 if (!Old->isImplicitAccess()) {
10501 Base = getDerived().TransformExpr(Old->getBase());
10502 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010503 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010504 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010505 Old->isArrow());
10506 if (Base.isInvalid())
10507 return ExprError();
10508 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010509 } else {
10510 BaseType = getDerived().TransformType(Old->getBaseType());
10511 }
John McCall10eae182009-11-30 22:42:35 +000010512
Douglas Gregor0da1d432011-02-28 20:01:57 +000010513 NestedNameSpecifierLoc QualifierLoc;
10514 if (Old->getQualifierLoc()) {
10515 QualifierLoc
10516 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10517 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010518 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010519 }
10520
Abramo Bagnara7945c982012-01-27 09:46:47 +000010521 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10522
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010523 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010524 Sema::LookupOrdinaryName);
10525
10526 // Transform all the decls.
10527 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10528 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010529 NamedDecl *InstD = static_cast<NamedDecl*>(
10530 getDerived().TransformDecl(Old->getMemberLoc(),
10531 *I));
John McCall84d87672009-12-10 09:41:52 +000010532 if (!InstD) {
10533 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10534 // This can happen because of dependent hiding.
10535 if (isa<UsingShadowDecl>(*I))
10536 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010537 else {
10538 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010539 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010540 }
John McCall84d87672009-12-10 09:41:52 +000010541 }
John McCall10eae182009-11-30 22:42:35 +000010542
10543 // Expand using declarations.
10544 if (isa<UsingDecl>(InstD)) {
10545 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010546 for (auto *I : UD->shadows())
10547 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010548 continue;
10549 }
10550
10551 R.addDecl(InstD);
10552 }
10553
10554 R.resolveKind();
10555
Douglas Gregor9262f472010-04-27 18:19:34 +000010556 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010557 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010558 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010559 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010560 Old->getMemberLoc(),
10561 Old->getNamingClass()));
10562 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010563 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010564
Douglas Gregorda7be082010-04-27 16:10:10 +000010565 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010566 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010567
John McCall10eae182009-11-30 22:42:35 +000010568 TemplateArgumentListInfo TransArgs;
10569 if (Old->hasExplicitTemplateArgs()) {
10570 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10571 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010572 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10573 Old->getNumTemplateArgs(),
10574 TransArgs))
10575 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010576 }
John McCall38836f02010-01-15 08:34:02 +000010577
10578 // FIXME: to do this check properly, we will need to preserve the
10579 // first-qualifier-in-scope here, just in case we had a dependent
10580 // base (and therefore couldn't do the check) and a
10581 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010582 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010583
John McCallb268a282010-08-23 23:25:46 +000010584 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010585 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010586 Old->getOperatorLoc(),
10587 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010588 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010589 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010590 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010591 R,
10592 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010593 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010594}
10595
10596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010597ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010598TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010599 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010600 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10601 if (SubExpr.isInvalid())
10602 return ExprError();
10603
10604 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010605 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010606
10607 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10608}
10609
10610template<typename Derived>
10611ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010612TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010613 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10614 if (Pattern.isInvalid())
10615 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010616
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010617 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010618 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010619
Douglas Gregorb8840002011-01-14 21:20:45 +000010620 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10621 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010622}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010623
10624template<typename Derived>
10625ExprResult
10626TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10627 // If E is not value-dependent, then nothing will change when we transform it.
10628 // Note: This is an instantiation-centric view.
10629 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010630 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010631
Richard Smithd784e682015-09-23 21:41:42 +000010632 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010633
Richard Smithd784e682015-09-23 21:41:42 +000010634 ArrayRef<TemplateArgument> PackArgs;
10635 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010636
Richard Smithd784e682015-09-23 21:41:42 +000010637 // Find the argument list to transform.
10638 if (E->isPartiallySubstituted()) {
10639 PackArgs = E->getPartialArguments();
10640 } else if (E->isValueDependent()) {
10641 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10642 bool ShouldExpand = false;
10643 bool RetainExpansion = false;
10644 Optional<unsigned> NumExpansions;
10645 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10646 Unexpanded,
10647 ShouldExpand, RetainExpansion,
10648 NumExpansions))
10649 return ExprError();
10650
10651 // If we need to expand the pack, build a template argument from it and
10652 // expand that.
10653 if (ShouldExpand) {
10654 auto *Pack = E->getPack();
10655 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10656 ArgStorage = getSema().Context.getPackExpansionType(
10657 getSema().Context.getTypeDeclType(TTPD), None);
10658 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10659 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10660 } else {
10661 auto *VD = cast<ValueDecl>(Pack);
10662 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10663 VK_RValue, E->getPackLoc());
10664 if (DRE.isInvalid())
10665 return ExprError();
10666 ArgStorage = new (getSema().Context) PackExpansionExpr(
10667 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10668 }
10669 PackArgs = ArgStorage;
10670 }
10671 }
10672
10673 // If we're not expanding the pack, just transform the decl.
10674 if (!PackArgs.size()) {
10675 auto *Pack = cast_or_null<NamedDecl>(
10676 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010677 if (!Pack)
10678 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010679 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10680 E->getPackLoc(),
10681 E->getRParenLoc(), None, None);
10682 }
10683
10684 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10685 E->getPackLoc());
10686 {
10687 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10688 typedef TemplateArgumentLocInventIterator<
10689 Derived, const TemplateArgument*> PackLocIterator;
10690 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10691 PackLocIterator(*this, PackArgs.end()),
10692 TransformedPackArgs, /*Uneval*/true))
10693 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010694 }
10695
Richard Smithd784e682015-09-23 21:41:42 +000010696 SmallVector<TemplateArgument, 8> Args;
10697 bool PartialSubstitution = false;
10698 for (auto &Loc : TransformedPackArgs.arguments()) {
10699 Args.push_back(Loc.getArgument());
10700 if (Loc.getArgument().isPackExpansion())
10701 PartialSubstitution = true;
10702 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010703
Richard Smithd784e682015-09-23 21:41:42 +000010704 if (PartialSubstitution)
10705 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10706 E->getPackLoc(),
10707 E->getRParenLoc(), None, Args);
10708
10709 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010710 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010711 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010712}
10713
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010714template<typename Derived>
10715ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010716TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10717 SubstNonTypeTemplateParmPackExpr *E) {
10718 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010719 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010720}
10721
10722template<typename Derived>
10723ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010724TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10725 SubstNonTypeTemplateParmExpr *E) {
10726 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010727 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010728}
10729
10730template<typename Derived>
10731ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010732TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10733 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010734 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010735}
10736
10737template<typename Derived>
10738ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010739TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10740 MaterializeTemporaryExpr *E) {
10741 return getDerived().TransformExpr(E->GetTemporaryExpr());
10742}
Chad Rosier1dcde962012-08-08 18:46:20 +000010743
Douglas Gregorfe314812011-06-21 17:03:29 +000010744template<typename Derived>
10745ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010746TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10747 Expr *Pattern = E->getPattern();
10748
10749 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10750 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10751 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10752
10753 // Determine whether the set of unexpanded parameter packs can and should
10754 // be expanded.
10755 bool Expand = true;
10756 bool RetainExpansion = false;
10757 Optional<unsigned> NumExpansions;
10758 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10759 Pattern->getSourceRange(),
10760 Unexpanded,
10761 Expand, RetainExpansion,
10762 NumExpansions))
10763 return true;
10764
10765 if (!Expand) {
10766 // Do not expand any packs here, just transform and rebuild a fold
10767 // expression.
10768 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10769
10770 ExprResult LHS =
10771 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10772 if (LHS.isInvalid())
10773 return true;
10774
10775 ExprResult RHS =
10776 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10777 if (RHS.isInvalid())
10778 return true;
10779
10780 if (!getDerived().AlwaysRebuild() &&
10781 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10782 return E;
10783
10784 return getDerived().RebuildCXXFoldExpr(
10785 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10786 RHS.get(), E->getLocEnd());
10787 }
10788
10789 // The transform has determined that we should perform an elementwise
10790 // expansion of the pattern. Do so.
10791 ExprResult Result = getDerived().TransformExpr(E->getInit());
10792 if (Result.isInvalid())
10793 return true;
10794 bool LeftFold = E->isLeftFold();
10795
10796 // If we're retaining an expansion for a right fold, it is the innermost
10797 // component and takes the init (if any).
10798 if (!LeftFold && RetainExpansion) {
10799 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10800
10801 ExprResult Out = getDerived().TransformExpr(Pattern);
10802 if (Out.isInvalid())
10803 return true;
10804
10805 Result = getDerived().RebuildCXXFoldExpr(
10806 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10807 Result.get(), E->getLocEnd());
10808 if (Result.isInvalid())
10809 return true;
10810 }
10811
10812 for (unsigned I = 0; I != *NumExpansions; ++I) {
10813 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10814 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10815 ExprResult Out = getDerived().TransformExpr(Pattern);
10816 if (Out.isInvalid())
10817 return true;
10818
10819 if (Out.get()->containsUnexpandedParameterPack()) {
10820 // We still have a pack; retain a pack expansion for this slice.
10821 Result = getDerived().RebuildCXXFoldExpr(
10822 E->getLocStart(),
10823 LeftFold ? Result.get() : Out.get(),
10824 E->getOperator(), E->getEllipsisLoc(),
10825 LeftFold ? Out.get() : Result.get(),
10826 E->getLocEnd());
10827 } else if (Result.isUsable()) {
10828 // We've got down to a single element; build a binary operator.
10829 Result = getDerived().RebuildBinaryOperator(
10830 E->getEllipsisLoc(), E->getOperator(),
10831 LeftFold ? Result.get() : Out.get(),
10832 LeftFold ? Out.get() : Result.get());
10833 } else
10834 Result = Out;
10835
10836 if (Result.isInvalid())
10837 return true;
10838 }
10839
10840 // If we're retaining an expansion for a left fold, it is the outermost
10841 // component and takes the complete expansion so far as its init (if any).
10842 if (LeftFold && RetainExpansion) {
10843 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10844
10845 ExprResult Out = getDerived().TransformExpr(Pattern);
10846 if (Out.isInvalid())
10847 return true;
10848
10849 Result = getDerived().RebuildCXXFoldExpr(
10850 E->getLocStart(), Result.get(),
10851 E->getOperator(), E->getEllipsisLoc(),
10852 Out.get(), E->getLocEnd());
10853 if (Result.isInvalid())
10854 return true;
10855 }
10856
10857 // If we had no init and an empty pack, and we're not retaining an expansion,
10858 // then produce a fallback value or error.
10859 if (Result.isUnset())
10860 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10861 E->getOperator());
10862
10863 return Result;
10864}
10865
10866template<typename Derived>
10867ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010868TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10869 CXXStdInitializerListExpr *E) {
10870 return getDerived().TransformExpr(E->getSubExpr());
10871}
10872
10873template<typename Derived>
10874ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010875TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010876 return SemaRef.MaybeBindToTemporary(E);
10877}
10878
10879template<typename Derived>
10880ExprResult
10881TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010882 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010883}
10884
10885template<typename Derived>
10886ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010887TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10888 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10889 if (SubExpr.isInvalid())
10890 return ExprError();
10891
10892 if (!getDerived().AlwaysRebuild() &&
10893 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010894 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010895
10896 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010897}
10898
10899template<typename Derived>
10900ExprResult
10901TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10902 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010903 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010904 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010905 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010906 /*IsCall=*/false, Elements, &ArgChanged))
10907 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010908
Ted Kremeneke65b0862012-03-06 20:05:56 +000010909 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10910 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010911
Ted Kremeneke65b0862012-03-06 20:05:56 +000010912 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10913 Elements.data(),
10914 Elements.size());
10915}
10916
10917template<typename Derived>
10918ExprResult
10919TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010920 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010921 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010922 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010923 bool ArgChanged = false;
10924 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10925 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010926
Ted Kremeneke65b0862012-03-06 20:05:56 +000010927 if (OrigElement.isPackExpansion()) {
10928 // This key/value element is a pack expansion.
10929 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10930 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10931 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10932 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10933
10934 // Determine whether the set of unexpanded parameter packs can
10935 // and should be expanded.
10936 bool Expand = true;
10937 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010938 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10939 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010940 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10941 OrigElement.Value->getLocEnd());
10942 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10943 PatternRange,
10944 Unexpanded,
10945 Expand, RetainExpansion,
10946 NumExpansions))
10947 return ExprError();
10948
10949 if (!Expand) {
10950 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010951 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010952 // expansion.
10953 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10954 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10955 if (Key.isInvalid())
10956 return ExprError();
10957
10958 if (Key.get() != OrigElement.Key)
10959 ArgChanged = true;
10960
10961 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10962 if (Value.isInvalid())
10963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010964
Ted Kremeneke65b0862012-03-06 20:05:56 +000010965 if (Value.get() != OrigElement.Value)
10966 ArgChanged = true;
10967
Chad Rosier1dcde962012-08-08 18:46:20 +000010968 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010969 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10970 };
10971 Elements.push_back(Expansion);
10972 continue;
10973 }
10974
10975 // Record right away that the argument was changed. This needs
10976 // to happen even if the array expands to nothing.
10977 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010978
Ted Kremeneke65b0862012-03-06 20:05:56 +000010979 // The transform has determined that we should perform an elementwise
10980 // expansion of the pattern. Do so.
10981 for (unsigned I = 0; I != *NumExpansions; ++I) {
10982 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10983 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10984 if (Key.isInvalid())
10985 return ExprError();
10986
10987 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10988 if (Value.isInvalid())
10989 return ExprError();
10990
Chad Rosier1dcde962012-08-08 18:46:20 +000010991 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010992 Key.get(), Value.get(), SourceLocation(), NumExpansions
10993 };
10994
10995 // If any unexpanded parameter packs remain, we still have a
10996 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010997 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010998 if (Key.get()->containsUnexpandedParameterPack() ||
10999 Value.get()->containsUnexpandedParameterPack())
11000 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011001
Ted Kremeneke65b0862012-03-06 20:05:56 +000011002 Elements.push_back(Element);
11003 }
11004
Richard Smith9467be42014-06-06 17:33:35 +000011005 // FIXME: Retain a pack expansion if RetainExpansion is true.
11006
Ted Kremeneke65b0862012-03-06 20:05:56 +000011007 // We've finished with this pack expansion.
11008 continue;
11009 }
11010
11011 // Transform and check key.
11012 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11013 if (Key.isInvalid())
11014 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011015
Ted Kremeneke65b0862012-03-06 20:05:56 +000011016 if (Key.get() != OrigElement.Key)
11017 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011018
Ted Kremeneke65b0862012-03-06 20:05:56 +000011019 // Transform and check value.
11020 ExprResult Value
11021 = getDerived().TransformExpr(OrigElement.Value);
11022 if (Value.isInvalid())
11023 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011024
Ted Kremeneke65b0862012-03-06 20:05:56 +000011025 if (Value.get() != OrigElement.Value)
11026 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011027
11028 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011029 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011030 };
11031 Elements.push_back(Element);
11032 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011033
Ted Kremeneke65b0862012-03-06 20:05:56 +000011034 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11035 return SemaRef.MaybeBindToTemporary(E);
11036
11037 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011038 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011039}
11040
Mike Stump11289f42009-09-09 15:08:12 +000011041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011043TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011044 TypeSourceInfo *EncodedTypeInfo
11045 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11046 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011048
Douglas Gregora16548e2009-08-11 05:31:07 +000011049 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011050 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011051 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011052
11053 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011054 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011055 E->getRParenLoc());
11056}
Mike Stump11289f42009-09-09 15:08:12 +000011057
Douglas Gregora16548e2009-08-11 05:31:07 +000011058template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011059ExprResult TreeTransform<Derived>::
11060TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011061 // This is a kind of implicit conversion, and it needs to get dropped
11062 // and recomputed for the same general reasons that ImplicitCastExprs
11063 // do, as well a more specific one: this expression is only valid when
11064 // it appears *immediately* as an argument expression.
11065 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011066}
11067
11068template<typename Derived>
11069ExprResult TreeTransform<Derived>::
11070TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011071 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011072 = getDerived().TransformType(E->getTypeInfoAsWritten());
11073 if (!TSInfo)
11074 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011075
John McCall31168b02011-06-15 23:02:42 +000011076 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011077 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011078 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011079
John McCall31168b02011-06-15 23:02:42 +000011080 if (!getDerived().AlwaysRebuild() &&
11081 TSInfo == E->getTypeInfoAsWritten() &&
11082 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011083 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011084
John McCall31168b02011-06-15 23:02:42 +000011085 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011086 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011087 Result.get());
11088}
11089
11090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011092TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011093 // Transform arguments.
11094 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011095 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011096 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011097 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011098 &ArgChanged))
11099 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011100
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011101 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11102 // Class message: transform the receiver type.
11103 TypeSourceInfo *ReceiverTypeInfo
11104 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11105 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011106 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011107
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011108 // If nothing changed, just retain the existing message send.
11109 if (!getDerived().AlwaysRebuild() &&
11110 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011111 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011112
11113 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011114 SmallVector<SourceLocation, 16> SelLocs;
11115 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011116 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11117 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011118 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011119 E->getMethodDecl(),
11120 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011121 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011122 E->getRightLoc());
11123 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011124 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11125 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11126 // Build a new class message send to 'super'.
11127 SmallVector<SourceLocation, 16> SelLocs;
11128 E->getSelectorLocs(SelLocs);
11129 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11130 E->getSelector(),
11131 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011132 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011133 E->getMethodDecl(),
11134 E->getLeftLoc(),
11135 Args,
11136 E->getRightLoc());
11137 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011138
11139 // Instance message: transform the receiver
11140 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11141 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011142 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011143 = getDerived().TransformExpr(E->getInstanceReceiver());
11144 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011145 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011146
11147 // If nothing changed, just retain the existing message send.
11148 if (!getDerived().AlwaysRebuild() &&
11149 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011150 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011151
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011152 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011153 SmallVector<SourceLocation, 16> SelLocs;
11154 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011155 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011156 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011157 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011158 E->getMethodDecl(),
11159 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011160 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011161 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011162}
11163
Mike Stump11289f42009-09-09 15:08:12 +000011164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011166TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011167 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011168}
11169
Mike Stump11289f42009-09-09 15:08:12 +000011170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011172TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011173 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011174}
11175
Mike Stump11289f42009-09-09 15:08:12 +000011176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011177ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011178TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011179 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011180 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011181 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011182 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011183
11184 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011185
Douglas Gregord51d90d2010-04-26 20:11:03 +000011186 // If nothing changed, just retain the existing expression.
11187 if (!getDerived().AlwaysRebuild() &&
11188 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011189 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011190
John McCallb268a282010-08-23 23:25:46 +000011191 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011192 E->getLocation(),
11193 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011194}
11195
Mike Stump11289f42009-09-09 15:08:12 +000011196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011198TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011199 // 'super' and types never change. Property never changes. Just
11200 // retain the existing expression.
11201 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011202 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011203
Douglas Gregor9faee212010-04-26 20:47:02 +000011204 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011205 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011206 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011207 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011208
Douglas Gregor9faee212010-04-26 20:47:02 +000011209 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011210
Douglas Gregor9faee212010-04-26 20:47:02 +000011211 // If nothing changed, just retain the existing expression.
11212 if (!getDerived().AlwaysRebuild() &&
11213 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011214 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011215
John McCallb7bd14f2010-12-02 01:19:52 +000011216 if (E->isExplicitProperty())
11217 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11218 E->getExplicitProperty(),
11219 E->getLocation());
11220
11221 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011222 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011223 E->getImplicitPropertyGetter(),
11224 E->getImplicitPropertySetter(),
11225 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011226}
11227
Mike Stump11289f42009-09-09 15:08:12 +000011228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011229ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011230TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11231 // Transform the base expression.
11232 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11233 if (Base.isInvalid())
11234 return ExprError();
11235
11236 // Transform the key expression.
11237 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11238 if (Key.isInvalid())
11239 return ExprError();
11240
11241 // If nothing changed, just retain the existing expression.
11242 if (!getDerived().AlwaysRebuild() &&
11243 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011244 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011245
Chad Rosier1dcde962012-08-08 18:46:20 +000011246 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011247 Base.get(), Key.get(),
11248 E->getAtIndexMethodDecl(),
11249 E->setAtIndexMethodDecl());
11250}
11251
11252template<typename Derived>
11253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011254TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011255 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011256 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011257 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011258 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011259
Douglas Gregord51d90d2010-04-26 20:11:03 +000011260 // If nothing changed, just retain the existing expression.
11261 if (!getDerived().AlwaysRebuild() &&
11262 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011263 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011264
John McCallb268a282010-08-23 23:25:46 +000011265 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011266 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011267 E->isArrow());
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
John McCall47f29ea2009-12-08 09:21:05 +000011272TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011273 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011274 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011275 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011276 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011277 SubExprs, &ArgumentChanged))
11278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011279
Douglas Gregora16548e2009-08-11 05:31:07 +000011280 if (!getDerived().AlwaysRebuild() &&
11281 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011282 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011283
Douglas Gregora16548e2009-08-11 05:31:07 +000011284 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011285 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011286 E->getRParenLoc());
11287}
11288
Mike Stump11289f42009-09-09 15:08:12 +000011289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011290ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011291TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11292 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11293 if (SrcExpr.isInvalid())
11294 return ExprError();
11295
11296 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11297 if (!Type)
11298 return ExprError();
11299
11300 if (!getDerived().AlwaysRebuild() &&
11301 Type == E->getTypeSourceInfo() &&
11302 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011303 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011304
11305 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11306 SrcExpr.get(), Type,
11307 E->getRParenLoc());
11308}
11309
11310template<typename Derived>
11311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011312TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011313 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011314
Craig Topperc3ec1492014-05-26 06:22:03 +000011315 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011316 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11317
11318 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011319 blockScope->TheDecl->setBlockMissingReturnType(
11320 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011321
Chris Lattner01cf8db2011-07-20 06:58:45 +000011322 SmallVector<ParmVarDecl*, 4> params;
11323 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011324
John McCallc8e321d2016-03-01 02:09:25 +000011325 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11326
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011327 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011328 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011329 if (getDerived().TransformFunctionTypeParams(
11330 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11331 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11332 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011333 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011334 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011335 }
John McCall490112f2011-02-04 18:33:18 +000011336
Eli Friedman34b49062012-01-26 03:00:14 +000011337 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011338 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011339
John McCallc8e321d2016-03-01 02:09:25 +000011340 auto epi = exprFunctionType->getExtProtoInfo();
11341 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11342
Jordan Rose5c382722013-03-08 21:51:21 +000011343 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011344 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011345 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011346
11347 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011348 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011349 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011350
11351 if (!oldBlock->blockMissingReturnType()) {
11352 blockScope->HasImplicitReturnType = false;
11353 blockScope->ReturnType = exprResultType;
11354 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011355
John McCall3882ace2011-01-05 12:14:39 +000011356 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011357 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011358 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011359 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011360 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011361 }
John McCall3882ace2011-01-05 12:14:39 +000011362
John McCall490112f2011-02-04 18:33:18 +000011363#ifndef NDEBUG
11364 // In builds with assertions, make sure that we captured everything we
11365 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011366 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011367 for (const auto &I : oldBlock->captures()) {
11368 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011369
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011370 // Ignore parameter packs.
11371 if (isa<ParmVarDecl>(oldCapture) &&
11372 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11373 continue;
John McCall490112f2011-02-04 18:33:18 +000011374
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011375 VarDecl *newCapture =
11376 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11377 oldCapture));
11378 assert(blockScope->CaptureMap.count(newCapture));
11379 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011380 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011381 }
11382#endif
11383
11384 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011385 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011386}
11387
Mike Stump11289f42009-09-09 15:08:12 +000011388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011389ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011390TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011391 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011392}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011393
11394template<typename Derived>
11395ExprResult
11396TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011397 QualType RetTy = getDerived().TransformType(E->getType());
11398 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011399 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011400 SubExprs.reserve(E->getNumSubExprs());
11401 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11402 SubExprs, &ArgumentChanged))
11403 return ExprError();
11404
11405 if (!getDerived().AlwaysRebuild() &&
11406 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011407 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011408
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011409 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011410 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011411}
Chad Rosier1dcde962012-08-08 18:46:20 +000011412
Douglas Gregora16548e2009-08-11 05:31:07 +000011413//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011414// Type reconstruction
11415//===----------------------------------------------------------------------===//
11416
Mike Stump11289f42009-09-09 15:08:12 +000011417template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011418QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11419 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011420 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011421 getDerived().getBaseEntity());
11422}
11423
Mike Stump11289f42009-09-09 15:08:12 +000011424template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011425QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11426 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011427 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011428 getDerived().getBaseEntity());
11429}
11430
Mike Stump11289f42009-09-09 15:08:12 +000011431template<typename Derived>
11432QualType
John McCall70dd5f62009-10-30 00:06:24 +000011433TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11434 bool WrittenAsLValue,
11435 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011436 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011437 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011438}
11439
11440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011441QualType
John McCall70dd5f62009-10-30 00:06:24 +000011442TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11443 QualType ClassType,
11444 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011445 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11446 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011447}
11448
11449template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011450QualType TreeTransform<Derived>::RebuildObjCObjectType(
11451 QualType BaseType,
11452 SourceLocation Loc,
11453 SourceLocation TypeArgsLAngleLoc,
11454 ArrayRef<TypeSourceInfo *> TypeArgs,
11455 SourceLocation TypeArgsRAngleLoc,
11456 SourceLocation ProtocolLAngleLoc,
11457 ArrayRef<ObjCProtocolDecl *> Protocols,
11458 ArrayRef<SourceLocation> ProtocolLocs,
11459 SourceLocation ProtocolRAngleLoc) {
11460 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11461 TypeArgs, TypeArgsRAngleLoc,
11462 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11463 ProtocolRAngleLoc,
11464 /*FailOnError=*/true);
11465}
11466
11467template<typename Derived>
11468QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11469 QualType PointeeType,
11470 SourceLocation Star) {
11471 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11472}
11473
11474template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011475QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011476TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11477 ArrayType::ArraySizeModifier SizeMod,
11478 const llvm::APInt *Size,
11479 Expr *SizeExpr,
11480 unsigned IndexTypeQuals,
11481 SourceRange BracketsRange) {
11482 if (SizeExpr || !Size)
11483 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11484 IndexTypeQuals, BracketsRange,
11485 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011486
11487 QualType Types[] = {
11488 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11489 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11490 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011491 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011492 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011493 QualType SizeType;
11494 for (unsigned I = 0; I != NumTypes; ++I)
11495 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11496 SizeType = Types[I];
11497 break;
11498 }
Mike Stump11289f42009-09-09 15:08:12 +000011499
Eli Friedman9562f392012-01-25 23:20:27 +000011500 // Note that we can return a VariableArrayType here in the case where
11501 // the element type was a dependent VariableArrayType.
11502 IntegerLiteral *ArraySize
11503 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11504 /*FIXME*/BracketsRange.getBegin());
11505 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011506 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011507 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011508}
Mike Stump11289f42009-09-09 15:08:12 +000011509
Douglas Gregord6ff3322009-08-04 16:50:30 +000011510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011511QualType
11512TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011513 ArrayType::ArraySizeModifier SizeMod,
11514 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011515 unsigned IndexTypeQuals,
11516 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011517 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011518 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011519}
11520
11521template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011522QualType
Mike Stump11289f42009-09-09 15:08:12 +000011523TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011524 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011525 unsigned IndexTypeQuals,
11526 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011527 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011528 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011529}
Mike Stump11289f42009-09-09 15:08:12 +000011530
Douglas Gregord6ff3322009-08-04 16:50:30 +000011531template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011532QualType
11533TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011534 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011535 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011536 unsigned IndexTypeQuals,
11537 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011538 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011539 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011540 IndexTypeQuals, BracketsRange);
11541}
11542
11543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011544QualType
11545TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011546 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011547 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011548 unsigned IndexTypeQuals,
11549 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011550 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011551 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011552 IndexTypeQuals, BracketsRange);
11553}
11554
11555template<typename Derived>
11556QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011557 unsigned NumElements,
11558 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011559 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011560 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011561}
Mike Stump11289f42009-09-09 15:08:12 +000011562
Douglas Gregord6ff3322009-08-04 16:50:30 +000011563template<typename Derived>
11564QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11565 unsigned NumElements,
11566 SourceLocation AttributeLoc) {
11567 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11568 NumElements, true);
11569 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011570 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11571 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011572 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011573}
Mike Stump11289f42009-09-09 15:08:12 +000011574
Douglas Gregord6ff3322009-08-04 16:50:30 +000011575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011576QualType
11577TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011578 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011579 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011580 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011581}
Mike Stump11289f42009-09-09 15:08:12 +000011582
Douglas Gregord6ff3322009-08-04 16:50:30 +000011583template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011584QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11585 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011586 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011587 const FunctionProtoType::ExtProtoInfo &EPI) {
11588 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011589 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011590 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011591 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011592}
Mike Stump11289f42009-09-09 15:08:12 +000011593
Douglas Gregord6ff3322009-08-04 16:50:30 +000011594template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011595QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11596 return SemaRef.Context.getFunctionNoProtoType(T);
11597}
11598
11599template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011600QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11601 assert(D && "no decl found");
11602 if (D->isInvalidDecl()) return QualType();
11603
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011604 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011605 TypeDecl *Ty;
11606 if (isa<UsingDecl>(D)) {
11607 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011608 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011609 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11610
11611 // A valid resolved using typename decl points to exactly one type decl.
11612 assert(++Using->shadow_begin() == Using->shadow_end());
11613 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011614
John McCallb96ec562009-12-04 22:46:56 +000011615 } else {
11616 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11617 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11618 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11619 }
11620
11621 return SemaRef.Context.getTypeDeclType(Ty);
11622}
11623
11624template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011625QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11626 SourceLocation Loc) {
11627 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011628}
11629
11630template<typename Derived>
11631QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11632 return SemaRef.Context.getTypeOfType(Underlying);
11633}
11634
11635template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011636QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11637 SourceLocation Loc) {
11638 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011639}
11640
11641template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011642QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11643 UnaryTransformType::UTTKind UKind,
11644 SourceLocation Loc) {
11645 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11646}
11647
11648template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011649QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011650 TemplateName Template,
11651 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011652 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011653 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011654}
Mike Stump11289f42009-09-09 15:08:12 +000011655
Douglas Gregor1135c352009-08-06 05:28:30 +000011656template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011657QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11658 SourceLocation KWLoc) {
11659 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11660}
11661
11662template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011663QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11664 SourceLocation KWLoc) {
11665 return SemaRef.BuildPipeType(ValueType, KWLoc);
11666}
11667
11668template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011669TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011670TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011671 bool TemplateKW,
11672 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011673 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011674 Template);
11675}
11676
11677template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011678TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011679TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11680 const IdentifierInfo &Name,
11681 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011682 QualType ObjectType,
11683 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011684 UnqualifiedId TemplateName;
11685 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011686 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011687 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011688 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011689 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011690 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011691 /*EnteringContext=*/false,
11692 Template);
John McCall31f82722010-11-12 08:19:04 +000011693 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011694}
Mike Stump11289f42009-09-09 15:08:12 +000011695
Douglas Gregora16548e2009-08-11 05:31:07 +000011696template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011697TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011698TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011699 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011700 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011701 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011702 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011703 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011704 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011705 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011706 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011707 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011708 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011709 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011710 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011711 /*EnteringContext=*/false,
11712 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011713 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011714}
Chad Rosier1dcde962012-08-08 18:46:20 +000011715
Douglas Gregor71395fa2009-11-04 00:56:37 +000011716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011717ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011718TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11719 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011720 Expr *OrigCallee,
11721 Expr *First,
11722 Expr *Second) {
11723 Expr *Callee = OrigCallee->IgnoreParenCasts();
11724 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011725
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011726 if (First->getObjectKind() == OK_ObjCProperty) {
11727 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11728 if (BinaryOperator::isAssignmentOp(Opc))
11729 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11730 First, Second);
11731 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11732 if (Result.isInvalid())
11733 return ExprError();
11734 First = Result.get();
11735 }
11736
11737 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11738 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11739 if (Result.isInvalid())
11740 return ExprError();
11741 Second = Result.get();
11742 }
11743
Douglas Gregora16548e2009-08-11 05:31:07 +000011744 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011745 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011746 if (!First->getType()->isOverloadableType() &&
11747 !Second->getType()->isOverloadableType())
11748 return getSema().CreateBuiltinArraySubscriptExpr(First,
11749 Callee->getLocStart(),
11750 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011751 } else if (Op == OO_Arrow) {
11752 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011753 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11754 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011755 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011756 // The argument is not of overloadable type, so try to create a
11757 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011758 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011759 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011760
John McCallb268a282010-08-23 23:25:46 +000011761 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011762 }
11763 } else {
John McCallb268a282010-08-23 23:25:46 +000011764 if (!First->getType()->isOverloadableType() &&
11765 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011766 // Neither of the arguments is an overloadable type, so try to
11767 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011768 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011769 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011770 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011771 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011773
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011774 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011775 }
11776 }
Mike Stump11289f42009-09-09 15:08:12 +000011777
11778 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011779 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011780 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011781
John McCallb268a282010-08-23 23:25:46 +000011782 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011783 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011784 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011785 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011786 // If we've resolved this to a particular non-member function, just call
11787 // that function. If we resolved it to a member function,
11788 // CreateOverloaded* will find that function for us.
11789 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11790 if (!isa<CXXMethodDecl>(ND))
11791 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011792 }
Mike Stump11289f42009-09-09 15:08:12 +000011793
Douglas Gregora16548e2009-08-11 05:31:07 +000011794 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011795 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011796 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011797
Douglas Gregora16548e2009-08-11 05:31:07 +000011798 // Create the overloaded operator invocation for unary operators.
11799 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011800 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011801 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011802 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011803 }
Mike Stump11289f42009-09-09 15:08:12 +000011804
Douglas Gregore9d62932011-07-15 16:25:15 +000011805 if (Op == OO_Subscript) {
11806 SourceLocation LBrace;
11807 SourceLocation RBrace;
11808
11809 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011810 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011811 LBrace = SourceLocation::getFromRawEncoding(
11812 NameLoc.CXXOperatorName.BeginOpNameLoc);
11813 RBrace = SourceLocation::getFromRawEncoding(
11814 NameLoc.CXXOperatorName.EndOpNameLoc);
11815 } else {
11816 LBrace = Callee->getLocStart();
11817 RBrace = OpLoc;
11818 }
11819
11820 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11821 First, Second);
11822 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011823
Douglas Gregora16548e2009-08-11 05:31:07 +000011824 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011825 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011826 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011827 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11828 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011830
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011831 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011832}
Mike Stump11289f42009-09-09 15:08:12 +000011833
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011834template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011835ExprResult
John McCallb268a282010-08-23 23:25:46 +000011836TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011837 SourceLocation OperatorLoc,
11838 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011839 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011840 TypeSourceInfo *ScopeType,
11841 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011842 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011843 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011844 QualType BaseType = Base->getType();
11845 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011846 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011847 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011848 !BaseType->getAs<PointerType>()->getPointeeType()
11849 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011850 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011851 return SemaRef.BuildPseudoDestructorExpr(
11852 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11853 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011854 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011855
Douglas Gregor678f90d2010-02-25 01:56:36 +000011856 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011857 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11858 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11859 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11860 NameInfo.setNamedTypeInfo(DestroyedType);
11861
Richard Smith8e4a3862012-05-15 06:15:11 +000011862 // The scope type is now known to be a valid nested name specifier
11863 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011864 if (ScopeType) {
11865 if (!ScopeType->getType()->getAs<TagType>()) {
11866 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11867 diag::err_expected_class_or_namespace)
11868 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11869 return ExprError();
11870 }
11871 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11872 CCLoc);
11873 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011874
Abramo Bagnara7945c982012-01-27 09:46:47 +000011875 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011876 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011877 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011878 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011879 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011880 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011881 /*TemplateArgs*/ nullptr,
11882 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011883}
11884
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011885template<typename Derived>
11886StmtResult
11887TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011888 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011889 CapturedDecl *CD = S->getCapturedDecl();
11890 unsigned NumParams = CD->getNumParams();
11891 unsigned ContextParamPos = CD->getContextParamPosition();
11892 SmallVector<Sema::CapturedParamNameType, 4> Params;
11893 for (unsigned I = 0; I < NumParams; ++I) {
11894 if (I != ContextParamPos) {
11895 Params.push_back(
11896 std::make_pair(
11897 CD->getParam(I)->getName(),
11898 getDerived().TransformType(CD->getParam(I)->getType())));
11899 } else {
11900 Params.push_back(std::make_pair(StringRef(), QualType()));
11901 }
11902 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011903 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011904 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011905 StmtResult Body;
11906 {
11907 Sema::CompoundScopeRAII CompoundScope(getSema());
11908 Body = getDerived().TransformStmt(S->getCapturedStmt());
11909 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011910
11911 if (Body.isInvalid()) {
11912 getSema().ActOnCapturedRegionError();
11913 return StmtError();
11914 }
11915
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011916 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011917}
11918
Douglas Gregord6ff3322009-08-04 16:50:30 +000011919} // end namespace clang
11920
Hans Wennborg59dbe862015-09-29 20:56:43 +000011921#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H