blob: 39f955b4c1ed7d92e3863092b379fd5828645dfc [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.
394 bool TransformExprs(Expr **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
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000851 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000855 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
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.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto 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 RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
Richard Smith9f690bd2015-10-27 06:02:45 +00001290 /// \brief Build a new co_return statement.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1295 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1296 }
1297
1298 /// \brief Build a new co_await expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1303 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1304 }
1305
1306 /// \brief Build a new co_yield expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1311 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1312 }
1313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001320 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001322 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001323 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001324 }
1325
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001326 /// \brief Rebuild an Objective-C exception declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new declaration.
1329 /// Subclasses may override this routine to provide different behavior.
1330 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1331 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001332 return getSema().BuildObjCExceptionDecl(TInfo, T,
1333 ExceptionDecl->getInnerLocStart(),
1334 ExceptionDecl->getLocation(),
1335 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001337
James Dennett2a4d13c2012-06-15 07:13:21 +00001338 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001343 SourceLocation RParenLoc,
1344 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001345 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001346 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001347 Var, Body);
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 \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001355 Stmt *Body) {
1356 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001358
James Dennett2a4d13c2012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Expr *Operand) {
1365 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001367
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001368 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001372 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001373 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001374 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001375 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001376 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001377 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001378 return getSema().ActOnOpenMPExecutableDirective(
1379 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 }
1381
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001382 /// \brief Build a new OpenMP 'if' clause.
1383 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001384 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001385 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001386 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1387 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001388 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389 SourceLocation NameModifierLoc,
1390 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001391 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1393 LParenLoc, NameModifierLoc, ColonLoc,
1394 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001395 }
1396
Alexey Bataev3778b602014-07-17 07:32:53 +00001397 /// \brief Build a new OpenMP 'final' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1402 SourceLocation LParenLoc,
1403 SourceLocation EndLoc) {
1404 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1405 EndLoc);
1406 }
1407
Alexey Bataev568a8332014-03-06 06:15:19 +00001408 /// \brief Build a new OpenMP 'num_threads' clause.
1409 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001410 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1413 SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1417 LParenLoc, EndLoc);
1418 }
1419
Alexey Bataev62c87d22014-03-21 04:51:18 +00001420 /// \brief Build a new OpenMP 'safelen' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1428 }
1429
Alexey Bataev66b15b52015-08-21 11:14:16 +00001430 /// \brief Build a new OpenMP 'simdlen' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexander Musman8bd31e62014-05-27 15:12:19 +00001440 /// \brief Build a new OpenMP 'collapse' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1445 SourceLocation LParenLoc,
1446 SourceLocation EndLoc) {
1447 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1448 EndLoc);
1449 }
1450
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001451 /// \brief Build a new OpenMP 'default' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1456 SourceLocation KindKwLoc,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1461 StartLoc, LParenLoc, EndLoc);
1462 }
1463
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001464 /// \brief Build a new OpenMP 'proc_bind' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001467 /// Subclasses may override this routine to provide different behavior.
1468 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1469 SourceLocation KindKwLoc,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1474 StartLoc, LParenLoc, EndLoc);
1475 }
1476
Alexey Bataev56dafe82014-06-20 07:16:17 +00001477 /// \brief Build a new OpenMP 'schedule' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new OpenMP clause.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1482 Expr *ChunkSize,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation KindLoc,
1486 SourceLocation CommaLoc,
1487 SourceLocation EndLoc) {
1488 return getSema().ActOnOpenMPScheduleClause(
1489 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1490 }
1491
Alexey Bataev10e775f2015-07-30 11:36:16 +00001492 /// \brief Build a new OpenMP 'ordered' clause.
1493 ///
1494 /// By default, performs semantic analysis to build the new OpenMP clause.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1497 SourceLocation EndLoc,
1498 SourceLocation LParenLoc, Expr *Num) {
1499 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1500 }
1501
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001502 /// \brief Build a new OpenMP 'private' clause.
1503 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001504 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001514 /// \brief Build a new OpenMP 'firstprivate' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001517 /// Subclasses may override this routine to provide different behavior.
1518 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexander Musman1bb328c2014-06-04 13:06:39 +00001526 /// \brief Build a new OpenMP 'lastprivate' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new OpenMP clause.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation EndLoc) {
1534 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1535 EndLoc);
1536 }
1537
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001538 /// \brief Build a new OpenMP 'shared' clause.
1539 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001540 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001541 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001542 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1543 SourceLocation StartLoc,
1544 SourceLocation LParenLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1547 EndLoc);
1548 }
1549
Alexey Bataevc5e02582014-06-16 07:08:35 +00001550 /// \brief Build a new OpenMP 'reduction' clause.
1551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1555 SourceLocation StartLoc,
1556 SourceLocation LParenLoc,
1557 SourceLocation ColonLoc,
1558 SourceLocation EndLoc,
1559 CXXScopeSpec &ReductionIdScopeSpec,
1560 const DeclarationNameInfo &ReductionId) {
1561 return getSema().ActOnOpenMPReductionClause(
1562 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1563 ReductionId);
1564 }
1565
Alexander Musman8dba6642014-04-22 13:09:42 +00001566 /// \brief Build a new OpenMP 'linear' clause.
1567 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001568 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001569 /// Subclasses may override this routine to provide different behavior.
1570 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1571 SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001573 OpenMPLinearClauseKind Modifier,
1574 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001575 SourceLocation ColonLoc,
1576 SourceLocation EndLoc) {
1577 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001578 Modifier, ModifierLoc, ColonLoc,
1579 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 }
1581
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001582 /// \brief Build a new OpenMP 'aligned' clause.
1583 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001584 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001585 /// Subclasses may override this routine to provide different behavior.
1586 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1587 SourceLocation StartLoc,
1588 SourceLocation LParenLoc,
1589 SourceLocation ColonLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1592 LParenLoc, ColonLoc, EndLoc);
1593 }
1594
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001595 /// \brief Build a new OpenMP 'copyin' clause.
1596 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001597 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataevbae9a792014-06-27 10:37:06 +00001607 /// \brief Build a new OpenMP 'copyprivate' clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataev6125da92014-07-21 11:26:11 +00001619 /// \brief Build a new OpenMP 'flush' pseudo 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 *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001631 /// \brief Build a new OpenMP 'depend' 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 *
1636 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1637 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1638 SourceLocation StartLoc, SourceLocation LParenLoc,
1639 SourceLocation EndLoc) {
1640 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1641 StartLoc, LParenLoc, EndLoc);
1642 }
1643
Michael Wonge710d542015-08-07 16:16:36 +00001644 /// \brief Build a new OpenMP 'device' clause.
1645 ///
1646 /// By default, performs semantic analysis to build the new statement.
1647 /// Subclasses may override this routine to provide different behavior.
1648 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1649 SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001651 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001652 EndLoc);
1653 }
1654
Kelvin Li0bff7af2015-11-23 05:32:03 +00001655 /// \brief Build a new OpenMP 'map' clause.
1656 ///
1657 /// By default, performs semantic analysis to build the new OpenMP clause.
1658 /// Subclasses may override this routine to provide different behavior.
1659 OMPClause *RebuildOMPMapClause(
1660 OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1661 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1662 SourceLocation StartLoc, SourceLocation LParenLoc,
1663 SourceLocation EndLoc) {
1664 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1665 ColonLoc, VarList,StartLoc,
1666 LParenLoc, EndLoc);
1667 }
1668
Kelvin Li099bb8c2015-11-24 20:50:12 +00001669 /// \brief Build a new OpenMP 'num_teams' clause.
1670 ///
1671 /// By default, performs semantic analysis to build the new statement.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1674 SourceLocation LParenLoc,
1675 SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1677 EndLoc);
1678 }
1679
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001680 /// \brief Build a new OpenMP 'thread_limit' clause.
1681 ///
1682 /// By default, performs semantic analysis to build the new statement.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1685 SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1689 LParenLoc, EndLoc);
1690 }
1691
Alexey Bataeva0569352015-12-01 10:17:31 +00001692 /// \brief Build a new OpenMP 'priority' clause.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1697 SourceLocation LParenLoc,
1698 SourceLocation EndLoc) {
1699 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1700 EndLoc);
1701 }
1702
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001703 /// \brief Build a new OpenMP 'grainsize' clause.
1704 ///
1705 /// By default, performs semantic analysis to build the new statement.
1706 /// Subclasses may override this routine to provide different behavior.
1707 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1708 SourceLocation LParenLoc,
1709 SourceLocation EndLoc) {
1710 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1711 EndLoc);
1712 }
1713
Alexey Bataev382967a2015-12-08 12:06:20 +00001714 /// \brief Build a new OpenMP 'num_tasks' clause.
1715 ///
1716 /// By default, performs semantic analysis to build the new statement.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation EndLoc) {
1721 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1722 EndLoc);
1723 }
1724
James Dennett2a4d13c2012-06-15 07:13:21 +00001725 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001726 ///
1727 /// By default, performs semantic analysis to build the new statement.
1728 /// Subclasses may override this routine to provide different behavior.
1729 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1730 Expr *object) {
1731 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1732 }
1733
James Dennett2a4d13c2012-06-15 07:13:21 +00001734 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001735 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001736 /// By default, performs semantic analysis to build the new statement.
1737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001738 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001739 Expr *Object, Stmt *Body) {
1740 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001741 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001742
James Dennett2a4d13c2012-06-15 07:13:21 +00001743 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001744 ///
1745 /// By default, performs semantic analysis to build the new statement.
1746 /// Subclasses may override this routine to provide different behavior.
1747 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1748 Stmt *Body) {
1749 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1750 }
John McCall53848232011-07-27 01:07:15 +00001751
Douglas Gregorf68a5082010-04-22 23:10:45 +00001752 /// \brief Build a new Objective-C fast enumeration statement.
1753 ///
1754 /// By default, performs semantic analysis to build the new statement.
1755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001756 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001757 Stmt *Element,
1758 Expr *Collection,
1759 SourceLocation RParenLoc,
1760 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001761 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001762 Element,
John McCallb268a282010-08-23 23:25:46 +00001763 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001764 RParenLoc);
1765 if (ForEachStmt.isInvalid())
1766 return StmtError();
1767
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001768 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001770
Douglas Gregorebe10102009-08-20 07:17:43 +00001771 /// \brief Build a new C++ exception declaration.
1772 ///
1773 /// By default, performs semantic analysis to build the new decaration.
1774 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001775 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001776 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001777 SourceLocation StartLoc,
1778 SourceLocation IdLoc,
1779 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001780 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001781 StartLoc, IdLoc, Id);
1782 if (Var)
1783 getSema().CurContext->addDecl(Var);
1784 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001785 }
1786
1787 /// \brief Build a new C++ catch statement.
1788 ///
1789 /// By default, performs semantic analysis to build the new statement.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001792 VarDecl *ExceptionDecl,
1793 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001794 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1795 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001796 }
Mike Stump11289f42009-09-09 15:08:12 +00001797
Douglas Gregorebe10102009-08-20 07:17:43 +00001798 /// \brief Build a new C++ try statement.
1799 ///
1800 /// By default, performs semantic analysis to build the new statement.
1801 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001802 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1803 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001804 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Richard Smith02e85f32011-04-14 22:09:26 +00001807 /// \brief Build a new C++0x range-based for statement.
1808 ///
1809 /// By default, performs semantic analysis to build the new statement.
1810 /// Subclasses may override this routine to provide different behavior.
1811 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001812 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001813 SourceLocation ColonLoc,
1814 Stmt *Range, Stmt *BeginEnd,
1815 Expr *Cond, Expr *Inc,
1816 Stmt *LoopVar,
1817 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001818 // If we've just learned that the range is actually an Objective-C
1819 // collection, treat this as an Objective-C fast enumeration loop.
1820 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1821 if (RangeStmt->isSingleDecl()) {
1822 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001823 if (RangeVar->isInvalidDecl())
1824 return StmtError();
1825
Douglas Gregorf7106af2013-04-08 18:40:13 +00001826 Expr *RangeExpr = RangeVar->getInit();
1827 if (!RangeExpr->isTypeDependent() &&
1828 RangeExpr->getType()->isObjCObjectPointerType())
1829 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1830 RParenLoc);
1831 }
1832 }
1833 }
1834
Richard Smithcfd53b42015-10-22 06:13:50 +00001835 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1836 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001837 Cond, Inc, LoopVar, RParenLoc,
1838 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001839 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001840
1841 /// \brief Build a new C++0x range-based for statement.
1842 ///
1843 /// By default, performs semantic analysis to build the new statement.
1844 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001845 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001846 bool IsIfExists,
1847 NestedNameSpecifierLoc QualifierLoc,
1848 DeclarationNameInfo NameInfo,
1849 Stmt *Nested) {
1850 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1851 QualifierLoc, NameInfo, Nested);
1852 }
1853
Richard Smith02e85f32011-04-14 22:09:26 +00001854 /// \brief Attach body to a C++0x range-based for statement.
1855 ///
1856 /// By default, performs semantic analysis to finish the new statement.
1857 /// Subclasses may override this routine to provide different behavior.
1858 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1859 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001861
David Majnemerfad8f482013-10-15 09:33:02 +00001862 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001863 Stmt *TryBlock, Stmt *Handler) {
1864 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001865 }
1866
David Majnemerfad8f482013-10-15 09:33:02 +00001867 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001868 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001869 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001870 }
1871
David Majnemerfad8f482013-10-15 09:33:02 +00001872 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001873 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001874 }
1875
Alexey Bataevec474782014-10-09 08:45:04 +00001876 /// \brief Build a new predefined expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
1880 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1881 PredefinedExpr::IdentType IT) {
1882 return getSema().BuildPredefinedExpr(Loc, IT);
1883 }
1884
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// \brief Build a new expression that references a declaration.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001890 LookupResult &R,
1891 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001892 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1893 }
1894
1895
1896 /// \brief Build a new expression that references a declaration.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001900 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001901 ValueDecl *VD,
1902 const DeclarationNameInfo &NameInfo,
1903 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001904 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001905 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001906
1907 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001908
1909 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 }
Mike Stump11289f42009-09-09 15:08:12 +00001911
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001916 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001918 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 }
1920
Douglas Gregorad8a3362009-09-04 17:36:40 +00001921 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001922 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001926 SourceLocation OperatorLoc,
1927 bool isArrow,
1928 CXXScopeSpec &SS,
1929 TypeSourceInfo *ScopeType,
1930 SourceLocation CCLoc,
1931 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001932 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001935 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 /// By default, performs semantic analysis to build the new expression.
1937 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001938 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001939 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001940 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001941 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregor882211c2010-04-28 22:16:22 +00001944 /// \brief Build a new builtin offsetof expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001948 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001949 TypeSourceInfo *Type,
1950 ArrayRef<Sema::OffsetOfComponent> Components,
1951 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001952 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001953 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001955
1956 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001957 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001958 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001961 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1962 SourceLocation OpLoc,
1963 UnaryExprOrTypeTrait ExprKind,
1964 SourceRange R) {
1965 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 }
1967
Peter Collingbournee190dee2011-03-11 19:24:49 +00001968 /// \brief Build a new sizeof, alignof or vec step expression with an
1969 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001970 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001973 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1974 UnaryExprOrTypeTrait ExprKind,
1975 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001977 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001980
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001981 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 }
Mike Stump11289f42009-09-09 15:08:12 +00001983
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001985 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001988 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001990 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001992 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001993 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 RBracketLoc);
1995 }
1996
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001997 /// \brief Build a new array section expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
2001 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2002 Expr *LowerBound,
2003 SourceLocation ColonLoc, Expr *Length,
2004 SourceLocation RBracketLoc) {
2005 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2006 ColonLoc, Length, RBracketLoc);
2007 }
2008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002015 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002016 Expr *ExecConfig = nullptr) {
2017 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002018 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 }
2020
2021 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002026 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002027 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002028 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002029 const DeclarationNameInfo &MemberNameInfo,
2030 ValueDecl *Member,
2031 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002032 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002033 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002034 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2035 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002036 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002037 // We have a reference to an unnamed field. This is always the
2038 // base of an anonymous struct/union member access, i.e. the
2039 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002040 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002041 assert(Member->getType()->isRecordType() &&
2042 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002043
Richard Smithcab9a7d2011-10-26 19:06:56 +00002044 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002045 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002046 QualifierLoc.getNestedNameSpecifier(),
2047 FoundDecl, Member);
2048 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002049 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002050 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002051 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002052 MemberExpr *ME = new (getSema().Context)
2053 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2054 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002055 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002056 }
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002058 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002059 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002060
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002061 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002062 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002063
John McCall16df1e52010-03-30 21:47:33 +00002064 // FIXME: this involves duplicating earlier analysis in a lot of
2065 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002066 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002067 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002068 R.resolveKind();
2069
John McCallb268a282010-08-23 23:25:46 +00002070 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002071 SS, TemplateKWLoc,
2072 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002073 R, ExplicitTemplateArgs,
2074 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 }
Mike Stump11289f42009-09-09 15:08:12 +00002076
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002078 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002082 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002083 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002084 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
2086
2087 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002092 SourceLocation QuestionLoc,
2093 Expr *LHS,
2094 SourceLocation ColonLoc,
2095 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002096 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2097 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 }
2099
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002101 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002104 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002105 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002107 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002108 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002109 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 }
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// By default, performs semantic analysis to build the new expression.
2115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002116 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002117 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002119 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002120 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002121 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 }
Mike Stump11289f42009-09-09 15:08:12 +00002123
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 SourceLocation OpLoc,
2130 SourceLocation AccessorLoc,
2131 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002132
John McCall10eae182009-11-30 22:42:35 +00002133 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002134 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002135 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002136 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002137 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002138 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002139 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002140 /* TemplateArgs */ nullptr,
2141 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 }
Mike Stump11289f42009-09-09 15:08:12 +00002143
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002145 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002148 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002149 MultiExprArg Inits,
2150 SourceLocation RBraceLoc,
2151 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002153 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002154 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002155 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002156
Douglas Gregord3d93062009-11-09 17:16:50 +00002157 // Patch in the result type we were given, which may have been computed
2158 // when the initial InitListExpr was built.
2159 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2160 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002161 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002165 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 MultiExprArg ArrayExprs,
2170 SourceLocation EqualOrColonLoc,
2171 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002172 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002175 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002178
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002179 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002183 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// By default, builds the implicit value initialization without performing
2185 /// any semantic analysis. Subclasses may override this routine to provide
2186 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002188 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002192 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002195 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002196 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002197 SourceLocation RParenLoc) {
2198 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002199 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002200 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 }
2202
2203 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002204 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002208 MultiExprArg SubExprs,
2209 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002210 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 }
Mike Stump11289f42009-09-09 15:08:12 +00002212
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002214 ///
2215 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 /// rather than attempting to map the label statement itself.
2217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002219 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002220 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002230 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 }
Mike Stump11289f42009-09-09 15:08:12 +00002232
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 /// \brief Build a new __builtin_choose_expr expression.
2234 ///
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002237 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002238 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 SourceLocation RParenLoc) {
2240 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002241 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 RParenLoc);
2243 }
Mike Stump11289f42009-09-09 15:08:12 +00002244
Peter Collingbourne91147592011-04-15 00:35:48 +00002245 /// \brief Build a new generic selection expression.
2246 ///
2247 /// By default, performs semantic analysis to build the new expression.
2248 /// Subclasses may override this routine to provide different behavior.
2249 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2250 SourceLocation DefaultLoc,
2251 SourceLocation RParenLoc,
2252 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002253 ArrayRef<TypeSourceInfo *> Types,
2254 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002255 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002256 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002257 }
2258
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 /// \brief Build a new overloaded operator call expression.
2260 ///
2261 /// By default, performs semantic analysis to build the new expression.
2262 /// The semantic analysis provides the behavior of template instantiation,
2263 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002264 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// argument-dependent lookup, etc. Subclasses may override this routine to
2266 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002267 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002269 Expr *Callee,
2270 Expr *First,
2271 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002272
2273 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// reinterpret_cast.
2275 ///
2276 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002277 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002279 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 Stmt::StmtClass Class,
2281 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002282 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 SourceLocation RAngleLoc,
2284 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002285 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 SourceLocation RParenLoc) {
2287 switch (Class) {
2288 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002289 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002290 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002291 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002292
2293 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002294 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002295 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002296 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002297
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002299 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002300 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002301 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002305 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002306 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002307 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002310 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 }
Mike Stump11289f42009-09-09 15:08:12 +00002313
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 /// \brief Build a new C++ static_cast expression.
2315 ///
2316 /// By default, performs semantic analysis to build the new expression.
2317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002318 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002320 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 SourceLocation RAngleLoc,
2322 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002323 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002325 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002326 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002327 SourceRange(LAngleLoc, RAngleLoc),
2328 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 }
2330
2331 /// \brief Build a new C++ dynamic_cast expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002335 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002337 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 SourceLocation RAngleLoc,
2339 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002340 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002342 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002343 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002344 SourceRange(LAngleLoc, RAngleLoc),
2345 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 }
2347
2348 /// \brief Build a new C++ reinterpret_cast expression.
2349 ///
2350 /// By default, performs semantic analysis to build the new expression.
2351 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002352 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002354 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 SourceLocation RAngleLoc,
2356 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002357 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002359 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002360 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002361 SourceRange(LAngleLoc, RAngleLoc),
2362 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 }
2364
2365 /// \brief Build a new C++ const_cast expression.
2366 ///
2367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002369 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002371 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 SourceLocation RAngleLoc,
2373 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002374 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002376 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002377 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002378 SourceRange(LAngleLoc, RAngleLoc),
2379 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 }
Mike Stump11289f42009-09-09 15:08:12 +00002381
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 /// \brief Build a new C++ functional-style cast expression.
2383 ///
2384 /// By default, performs semantic analysis to build the new expression.
2385 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002386 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2387 SourceLocation LParenLoc,
2388 Expr *Sub,
2389 SourceLocation RParenLoc) {
2390 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002391 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 RParenLoc);
2393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 /// \brief Build a new C++ typeid(type) expression.
2396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002399 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002400 SourceLocation TypeidLoc,
2401 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002403 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002404 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
Mike Stump11289f42009-09-09 15:08:12 +00002406
Francois Pichet9f4f2072010-09-08 12:20:18 +00002407
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 /// \brief Build a new C++ typeid(expr) expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002412 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002413 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002414 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002416 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002417 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002418 }
2419
Francois Pichet9f4f2072010-09-08 12:20:18 +00002420 /// \brief Build a new C++ __uuidof(type) expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
2424 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2425 SourceLocation TypeidLoc,
2426 TypeSourceInfo *Operand,
2427 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002428 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002429 RParenLoc);
2430 }
2431
2432 /// \brief Build a new C++ __uuidof(expr) expression.
2433 ///
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
2436 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2437 SourceLocation TypeidLoc,
2438 Expr *Operand,
2439 SourceLocation RParenLoc) {
2440 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2441 RParenLoc);
2442 }
2443
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 /// \brief Build a new C++ "this" expression.
2445 ///
2446 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002447 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002448 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002449 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002450 QualType ThisType,
2451 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002452 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002453 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 }
2455
2456 /// \brief Build a new C++ throw expression.
2457 ///
2458 /// By default, performs semantic analysis to build the new expression.
2459 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002460 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2461 bool IsThrownVariableInScope) {
2462 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
2464
2465 /// \brief Build a new C++ default-argument expression.
2466 ///
2467 /// By default, builds a new default-argument expression, which does not
2468 /// require any semantic analysis. Subclasses may override this routine to
2469 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002470 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002471 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002472 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 }
2474
Richard Smith852c9db2013-04-20 22:23:05 +00002475 /// \brief Build a new C++11 default-initialization expression.
2476 ///
2477 /// By default, builds a new default field initialization expression, which
2478 /// does not require any semantic analysis. Subclasses may override this
2479 /// routine to provide different behavior.
2480 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2481 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002482 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002483 }
2484
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 /// \brief Build a new C++ zero-initialization expression.
2486 ///
2487 /// By default, performs semantic analysis to build the new expression.
2488 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002489 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2490 SourceLocation LParenLoc,
2491 SourceLocation RParenLoc) {
2492 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002493 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 }
Mike Stump11289f42009-09-09 15:08:12 +00002495
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 /// \brief Build a new C++ "new" expression.
2497 ///
2498 /// By default, performs semantic analysis to build the new expression.
2499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002500 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002501 bool UseGlobal,
2502 SourceLocation PlacementLParen,
2503 MultiExprArg PlacementArgs,
2504 SourceLocation PlacementRParen,
2505 SourceRange TypeIdParens,
2506 QualType AllocatedType,
2507 TypeSourceInfo *AllocatedTypeInfo,
2508 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002509 SourceRange DirectInitRange,
2510 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002511 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002513 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002515 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002516 AllocatedType,
2517 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002518 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002519 DirectInitRange,
2520 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 }
Mike Stump11289f42009-09-09 15:08:12 +00002522
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 /// \brief Build a new C++ "delete" expression.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002527 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002528 bool IsGlobalDelete,
2529 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002530 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002532 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 }
Mike Stump11289f42009-09-09 15:08:12 +00002534
Douglas Gregor29c42f22012-02-24 07:38:34 +00002535 /// \brief Build a new type trait expression.
2536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
2539 ExprResult RebuildTypeTrait(TypeTrait Trait,
2540 SourceLocation StartLoc,
2541 ArrayRef<TypeSourceInfo *> Args,
2542 SourceLocation RParenLoc) {
2543 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002545
John Wiegley6242b6a2011-04-28 00:16:57 +00002546 /// \brief Build a new array type trait expression.
2547 ///
2548 /// By default, performs semantic analysis to build the new expression.
2549 /// Subclasses may override this routine to provide different behavior.
2550 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2551 SourceLocation StartLoc,
2552 TypeSourceInfo *TSInfo,
2553 Expr *DimExpr,
2554 SourceLocation RParenLoc) {
2555 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2556 }
2557
John Wiegleyf9f65842011-04-25 06:54:41 +00002558 /// \brief Build a new expression trait expression.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
2562 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2563 SourceLocation StartLoc,
2564 Expr *Queried,
2565 SourceLocation RParenLoc) {
2566 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2567 }
2568
Mike Stump11289f42009-09-09 15:08:12 +00002569 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 /// expression.
2571 ///
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002574 ExprResult RebuildDependentScopeDeclRefExpr(
2575 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002576 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002577 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002578 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002579 bool IsAddressOfOperand,
2580 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002582 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002583
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002584 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002585 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2586 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002587
Reid Kleckner32506ed2014-06-12 23:03:48 +00002588 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002589 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 }
2591
2592 /// \brief Build a new template-id expression.
2593 ///
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002596 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002597 SourceLocation TemplateKWLoc,
2598 LookupResult &R,
2599 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002600 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002601 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2602 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002603 }
2604
2605 /// \brief Build a new object-construction expression.
2606 ///
2607 /// By default, performs semantic analysis to build the new expression.
2608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002609 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002610 SourceLocation Loc,
2611 CXXConstructorDecl *Constructor,
2612 bool IsElidable,
2613 MultiExprArg Args,
2614 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002615 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002616 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002617 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002618 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002619 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002620 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002621 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002622 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002623 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002624
Douglas Gregordb121ba2009-12-14 16:27:04 +00002625 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002626 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002627 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002628 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002629 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002630 RequiresZeroInit, ConstructKind,
2631 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002632 }
2633
2634 /// \brief Build a new object-construction expression.
2635 ///
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002638 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2639 SourceLocation LParenLoc,
2640 MultiExprArg Args,
2641 SourceLocation RParenLoc) {
2642 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002643 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002644 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002645 RParenLoc);
2646 }
2647
2648 /// \brief Build a new object-construction expression.
2649 ///
2650 /// By default, performs semantic analysis to build the new expression.
2651 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002652 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2653 SourceLocation LParenLoc,
2654 MultiExprArg Args,
2655 SourceLocation RParenLoc) {
2656 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002657 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002658 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 RParenLoc);
2660 }
Mike Stump11289f42009-09-09 15:08:12 +00002661
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 /// \brief Build a new member reference expression.
2663 ///
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002666 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002667 QualType BaseType,
2668 bool IsArrow,
2669 SourceLocation OperatorLoc,
2670 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002671 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002672 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002673 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002674 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002676 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002677
John McCallb268a282010-08-23 23:25:46 +00002678 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002679 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002680 SS, TemplateKWLoc,
2681 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002682 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002683 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002684 }
2685
John McCall10eae182009-11-30 22:42:35 +00002686 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002690 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2691 SourceLocation OperatorLoc,
2692 bool IsArrow,
2693 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002694 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002695 NamedDecl *FirstQualifierInScope,
2696 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002697 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002698 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002699 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002700
John McCallb268a282010-08-23 23:25:46 +00002701 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002702 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002703 SS, TemplateKWLoc,
2704 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002705 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002708 /// \brief Build a new noexcept expression.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2712 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2713 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2714 }
2715
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002716 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002717 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2718 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002719 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002720 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002721 Optional<unsigned> Length,
2722 ArrayRef<TemplateArgument> PartialArgs) {
2723 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2724 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002725 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002726
Patrick Beard0caa3942012-04-19 00:25:12 +00002727 /// \brief Build a new Objective-C boxed expression.
2728 ///
2729 /// By default, performs semantic analysis to build the new expression.
2730 /// Subclasses may override this routine to provide different behavior.
2731 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2732 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002734
Ted Kremeneke65b0862012-03-06 20:05:56 +00002735 /// \brief Build a new Objective-C array literal.
2736 ///
2737 /// By default, performs semantic analysis to build the new expression.
2738 /// Subclasses may override this routine to provide different behavior.
2739 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2740 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002741 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002742 MultiExprArg(Elements, NumElements));
2743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002744
2745 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002746 Expr *Base, Expr *Key,
2747 ObjCMethodDecl *getterMethod,
2748 ObjCMethodDecl *setterMethod) {
2749 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2750 getterMethod, setterMethod);
2751 }
2752
2753 /// \brief Build a new Objective-C dictionary literal.
2754 ///
2755 /// By default, performs semantic analysis to build the new expression.
2756 /// Subclasses may override this routine to provide different behavior.
2757 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2758 ObjCDictionaryElement *Elements,
2759 unsigned NumElements) {
2760 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002762
James Dennett2a4d13c2012-06-15 07:13:21 +00002763 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002764 ///
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002767 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002768 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002769 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002770 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002771 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002772
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002773 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002774 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002775 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002776 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002777 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002778 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002779 MultiExprArg Args,
2780 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002781 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2782 ReceiverTypeInfo->getType(),
2783 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002784 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002785 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002786 }
2787
2788 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002789 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002790 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002791 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002792 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002793 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002794 MultiExprArg Args,
2795 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002796 return SemaRef.BuildInstanceMessage(Receiver,
2797 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002798 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002799 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002800 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002801 }
2802
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002803 /// \brief Build a new Objective-C instance/class message to 'super'.
2804 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2805 Selector Sel,
2806 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002807 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002808 ObjCMethodDecl *Method,
2809 SourceLocation LBracLoc,
2810 MultiExprArg Args,
2811 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002812 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002813 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002814 SuperLoc,
2815 Sel, Method, LBracLoc, SelectorLocs,
2816 RBracLoc, Args)
2817 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002818 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002819 SuperLoc,
2820 Sel, Method, LBracLoc, SelectorLocs,
2821 RBracLoc, Args);
2822
2823
2824 }
2825
Douglas Gregord51d90d2010-04-26 20:11:03 +00002826 /// \brief Build a new Objective-C ivar reference expression.
2827 ///
2828 /// By default, performs semantic analysis to build the new expression.
2829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002830 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002831 SourceLocation IvarLoc,
2832 bool IsArrow, bool IsFreeIvar) {
2833 // FIXME: We lose track of the IsFreeIvar bit.
2834 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002835 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2836 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002837 /*FIXME:*/IvarLoc, IsArrow,
2838 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002839 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002840 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002841 /*TemplateArgs=*/nullptr,
2842 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002843 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002844
2845 /// \brief Build a new Objective-C property reference expression.
2846 ///
2847 /// By default, performs semantic analysis to build the new expression.
2848 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002849 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002850 ObjCPropertyDecl *Property,
2851 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002852 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002853 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2854 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2855 /*FIXME:*/PropertyLoc,
2856 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002857 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002858 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002859 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002860 /*TemplateArgs=*/nullptr,
2861 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002863
John McCallb7bd14f2010-12-02 01:19:52 +00002864 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002865 ///
2866 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002867 /// Subclasses may override this routine to provide different behavior.
2868 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2869 ObjCMethodDecl *Getter,
2870 ObjCMethodDecl *Setter,
2871 SourceLocation PropertyLoc) {
2872 // Since these expressions can only be value-dependent, we do not
2873 // need to perform semantic analysis again.
2874 return Owned(
2875 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2876 VK_LValue, OK_ObjCProperty,
2877 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002878 }
2879
Douglas Gregord51d90d2010-04-26 20:11:03 +00002880 /// \brief Build a new Objective-C "isa" expression.
2881 ///
2882 /// By default, performs semantic analysis to build the new expression.
2883 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002884 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002885 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002886 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002887 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2888 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002889 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002890 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002891 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002892 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002893 /*TemplateArgs=*/nullptr,
2894 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002896
Douglas Gregora16548e2009-08-11 05:31:07 +00002897 /// \brief Build a new shuffle vector expression.
2898 ///
2899 /// By default, performs semantic analysis to build the new expression.
2900 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002901 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002902 MultiExprArg SubExprs,
2903 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002904 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002905 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002906 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2907 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2908 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002909 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002910
Douglas Gregora16548e2009-08-11 05:31:07 +00002911 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002912 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002913 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2914 SemaRef.Context.BuiltinFnTy,
2915 VK_RValue, BuiltinLoc);
2916 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2917 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002918 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002919
2920 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002921 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002922 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002923 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002924
Douglas Gregora16548e2009-08-11 05:31:07 +00002925 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002926 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002927 }
John McCall31f82722010-11-12 08:19:04 +00002928
Hal Finkelc4d7c822013-09-18 03:29:45 +00002929 /// \brief Build a new convert vector expression.
2930 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2931 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2932 SourceLocation RParenLoc) {
2933 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2934 BuiltinLoc, RParenLoc);
2935 }
2936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 /// \brief Build a new template argument pack expansion.
2938 ///
2939 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002940 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002941 /// different behavior.
2942 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002943 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002944 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002945 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002946 case TemplateArgument::Expression: {
2947 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002948 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2949 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002950 if (Result.isInvalid())
2951 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002952
Douglas Gregor98318c22011-01-03 21:37:45 +00002953 return TemplateArgumentLoc(Result.get(), Result.get());
2954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002955
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002956 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002957 return TemplateArgumentLoc(TemplateArgument(
2958 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002959 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002960 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002961 Pattern.getTemplateNameLoc(),
2962 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002963
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002964 case TemplateArgument::Null:
2965 case TemplateArgument::Integral:
2966 case TemplateArgument::Declaration:
2967 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002968 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002969 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002970 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002972 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002973 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002974 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002975 EllipsisLoc,
2976 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002977 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2978 Expansion);
2979 break;
2980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002982 return TemplateArgumentLoc();
2983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregor968f23a2011-01-03 19:31:53 +00002985 /// \brief Build a new expression pack expansion.
2986 ///
2987 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002988 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002989 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002990 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002991 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002992 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002993 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002994
Richard Smith0f0af192014-11-08 05:07:16 +00002995 /// \brief Build a new C++1z fold-expression.
2996 ///
2997 /// By default, performs semantic analysis in order to build a new fold
2998 /// expression.
2999 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3000 BinaryOperatorKind Operator,
3001 SourceLocation EllipsisLoc, Expr *RHS,
3002 SourceLocation RParenLoc) {
3003 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3004 RHS, RParenLoc);
3005 }
3006
3007 /// \brief Build an empty C++1z fold-expression with the given operator.
3008 ///
3009 /// By default, produces the fallback value for the fold-expression, or
3010 /// produce an error if there is no fallback value.
3011 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3012 BinaryOperatorKind Operator) {
3013 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3014 }
3015
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003016 /// \brief Build a new atomic operation expression.
3017 ///
3018 /// By default, performs semantic analysis to build the new expression.
3019 /// Subclasses may override this routine to provide different behavior.
3020 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3021 MultiExprArg SubExprs,
3022 QualType RetTy,
3023 AtomicExpr::AtomicOp Op,
3024 SourceLocation RParenLoc) {
3025 // Just create the expression; there is not any interesting semantic
3026 // analysis here because we can't actually build an AtomicExpr until
3027 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003028 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003029 RParenLoc);
3030 }
3031
John McCall31f82722010-11-12 08:19:04 +00003032private:
Douglas Gregor14454802011-02-25 02:25:35 +00003033 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3034 QualType ObjectType,
3035 NamedDecl *FirstQualifierInScope,
3036 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003037
3038 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3039 QualType ObjectType,
3040 NamedDecl *FirstQualifierInScope,
3041 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003042
3043 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3044 NamedDecl *FirstQualifierInScope,
3045 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003046};
Douglas Gregora16548e2009-08-11 05:31:07 +00003047
Douglas Gregorebe10102009-08-20 07:17:43 +00003048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003049StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003050 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003051 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003052
Douglas Gregorebe10102009-08-20 07:17:43 +00003053 switch (S->getStmtClass()) {
3054 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregorebe10102009-08-20 07:17:43 +00003056 // Transform individual statement nodes
3057#define STMT(Node, Parent) \
3058 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003059#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003060#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003061#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003062
Douglas Gregorebe10102009-08-20 07:17:43 +00003063 // Transform expressions by calling TransformExpr.
3064#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003065#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003066#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003067#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003068 {
John McCalldadc5752010-08-24 06:29:42 +00003069 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003070 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003071 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003072
Richard Smith945f8d32013-01-14 22:39:08 +00003073 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003074 }
Mike Stump11289f42009-09-09 15:08:12 +00003075 }
3076
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003077 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003078}
Mike Stump11289f42009-09-09 15:08:12 +00003079
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003080template<typename Derived>
3081OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3082 if (!S)
3083 return S;
3084
3085 switch (S->getClauseKind()) {
3086 default: break;
3087 // Transform individual clause nodes
3088#define OPENMP_CLAUSE(Name, Class) \
3089 case OMPC_ ## Name : \
3090 return getDerived().Transform ## Class(cast<Class>(S));
3091#include "clang/Basic/OpenMPKinds.def"
3092 }
3093
3094 return S;
3095}
3096
Mike Stump11289f42009-09-09 15:08:12 +00003097
Douglas Gregore922c772009-08-04 22:27:00 +00003098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003099ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003100 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003101 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003102
3103 switch (E->getStmtClass()) {
3104 case Stmt::NoStmtClass: break;
3105#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003106#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003107#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003108 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003109#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003110 }
3111
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003112 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003113}
3114
3115template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003116ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003117 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003118 // Initializers are instantiated like expressions, except that various outer
3119 // layers are stripped.
3120 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003121 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003122
3123 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3124 Init = ExprTemp->getSubExpr();
3125
Richard Smithe6ca4752013-05-30 22:40:16 +00003126 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3127 Init = MTE->GetTemporaryExpr();
3128
Richard Smithd59b8322012-12-19 01:39:02 +00003129 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3130 Init = Binder->getSubExpr();
3131
3132 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3133 Init = ICE->getSubExprAsWritten();
3134
Richard Smithcc1b96d2013-06-12 22:31:48 +00003135 if (CXXStdInitializerListExpr *ILE =
3136 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003137 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003138
Richard Smithc6abd962014-07-25 01:12:44 +00003139 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003140 // InitListExprs. Other forms of copy-initialization will be a no-op if
3141 // the initializer is already the right type.
3142 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003143 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003144 return getDerived().TransformExpr(Init);
3145
3146 // Revert value-initialization back to empty parens.
3147 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3148 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003149 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003150 Parens.getEnd());
3151 }
3152
3153 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3154 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003155 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003156 SourceLocation());
3157
3158 // Revert initialization by constructor back to a parenthesized or braced list
3159 // of expressions. Any other form of initializer can just be reused directly.
3160 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003161 return getDerived().TransformExpr(Init);
3162
Richard Smithf8adcdc2014-07-17 05:12:35 +00003163 // If the initialization implicitly converted an initializer list to a
3164 // std::initializer_list object, unwrap the std::initializer_list too.
3165 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003166 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003167
Richard Smithd59b8322012-12-19 01:39:02 +00003168 SmallVector<Expr*, 8> NewArgs;
3169 bool ArgChanged = false;
3170 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003171 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003172 return ExprError();
3173
3174 // If this was list initialization, revert to list form.
3175 if (Construct->isListInitialization())
3176 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3177 Construct->getLocEnd(),
3178 Construct->getType());
3179
Richard Smithd59b8322012-12-19 01:39:02 +00003180 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003181 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003182 if (Parens.isInvalid()) {
3183 // This was a variable declaration's initialization for which no initializer
3184 // was specified.
3185 assert(NewArgs.empty() &&
3186 "no parens or braces but have direct init with arguments?");
3187 return ExprEmpty();
3188 }
Richard Smithd59b8322012-12-19 01:39:02 +00003189 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3190 Parens.getEnd());
3191}
3192
3193template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003194bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3195 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003196 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003197 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003198 bool *ArgChanged) {
3199 for (unsigned I = 0; I != NumInputs; ++I) {
3200 // If requested, drop call arguments that need to be dropped.
3201 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3202 if (ArgChanged)
3203 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregora3efea12011-01-03 19:04:46 +00003205 break;
3206 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor968f23a2011-01-03 19:31:53 +00003208 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3209 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003210
Chris Lattner01cf8db2011-07-20 06:58:45 +00003211 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003212 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3213 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003214
Douglas Gregor968f23a2011-01-03 19:31:53 +00003215 // Determine whether the set of unexpanded parameter packs can and should
3216 // be expanded.
3217 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003218 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003219 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3220 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003221 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3222 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003223 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003224 Expand, RetainExpansion,
3225 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003226 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
Douglas Gregor968f23a2011-01-03 19:31:53 +00003228 if (!Expand) {
3229 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003230 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003231 // expansion.
3232 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3233 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3234 if (OutPattern.isInvalid())
3235 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
3237 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003238 Expansion->getEllipsisLoc(),
3239 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003240 if (Out.isInvalid())
3241 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003242
Douglas Gregor968f23a2011-01-03 19:31:53 +00003243 if (ArgChanged)
3244 *ArgChanged = true;
3245 Outputs.push_back(Out.get());
3246 continue;
3247 }
John McCall542e7c62011-07-06 07:30:07 +00003248
3249 // Record right away that the argument was changed. This needs
3250 // to happen even if the array expands to nothing.
3251 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregor968f23a2011-01-03 19:31:53 +00003253 // The transform has determined that we should perform an elementwise
3254 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003255 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003256 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3257 ExprResult Out = getDerived().TransformExpr(Pattern);
3258 if (Out.isInvalid())
3259 return true;
3260
Richard Smith9467be42014-06-06 17:33:35 +00003261 // FIXME: Can this happen? We should not try to expand the pack
3262 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003263 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003264 Out = getDerived().RebuildPackExpansion(
3265 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003266 if (Out.isInvalid())
3267 return true;
3268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003269
Douglas Gregor968f23a2011-01-03 19:31:53 +00003270 Outputs.push_back(Out.get());
3271 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003272
Richard Smith9467be42014-06-06 17:33:35 +00003273 // If we're supposed to retain a pack expansion, do so by temporarily
3274 // forgetting the partially-substituted parameter pack.
3275 if (RetainExpansion) {
3276 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3277
3278 ExprResult Out = getDerived().TransformExpr(Pattern);
3279 if (Out.isInvalid())
3280 return true;
3281
3282 Out = getDerived().RebuildPackExpansion(
3283 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3284 if (Out.isInvalid())
3285 return true;
3286
3287 Outputs.push_back(Out.get());
3288 }
3289
Douglas Gregor968f23a2011-01-03 19:31:53 +00003290 continue;
3291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Richard Smithd59b8322012-12-19 01:39:02 +00003293 ExprResult Result =
3294 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3295 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003296 if (Result.isInvalid())
3297 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003298
Douglas Gregora3efea12011-01-03 19:04:46 +00003299 if (Result.get() != Inputs[I] && ArgChanged)
3300 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
3302 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregora3efea12011-01-03 19:04:46 +00003305 return false;
3306}
3307
3308template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003309NestedNameSpecifierLoc
3310TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3311 NestedNameSpecifierLoc NNS,
3312 QualType ObjectType,
3313 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003314 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003315 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003316 Qualifier = Qualifier.getPrefix())
3317 Qualifiers.push_back(Qualifier);
3318
3319 CXXScopeSpec SS;
3320 while (!Qualifiers.empty()) {
3321 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3322 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregor14454802011-02-25 02:25:35 +00003324 switch (QNNS->getKind()) {
3325 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003326 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003327 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003328 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003329 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003330 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003331 FirstQualifierInScope, false))
3332 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
Douglas Gregor14454802011-02-25 02:25:35 +00003334 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor14454802011-02-25 02:25:35 +00003336 case NestedNameSpecifier::Namespace: {
3337 NamespaceDecl *NS
3338 = cast_or_null<NamespaceDecl>(
3339 getDerived().TransformDecl(
3340 Q.getLocalBeginLoc(),
3341 QNNS->getAsNamespace()));
3342 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3343 break;
3344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor14454802011-02-25 02:25:35 +00003346 case NestedNameSpecifier::NamespaceAlias: {
3347 NamespaceAliasDecl *Alias
3348 = cast_or_null<NamespaceAliasDecl>(
3349 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3350 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003351 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003352 Q.getLocalEndLoc());
3353 break;
3354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregor14454802011-02-25 02:25:35 +00003356 case NestedNameSpecifier::Global:
3357 // There is no meaningful transformation that one could perform on the
3358 // global scope.
3359 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3360 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Nikola Smiljanic67860242014-09-26 00:28:20 +00003362 case NestedNameSpecifier::Super: {
3363 CXXRecordDecl *RD =
3364 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3365 SourceLocation(), QNNS->getAsRecordDecl()));
3366 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3367 break;
3368 }
3369
Douglas Gregor14454802011-02-25 02:25:35 +00003370 case NestedNameSpecifier::TypeSpecWithTemplate:
3371 case NestedNameSpecifier::TypeSpec: {
3372 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3373 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregor14454802011-02-25 02:25:35 +00003375 if (!TL)
3376 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003377
Douglas Gregor14454802011-02-25 02:25:35 +00003378 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003379 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003380 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003381 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003382 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003383 if (TL.getType()->isEnumeralType())
3384 SemaRef.Diag(TL.getBeginLoc(),
3385 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003386 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3387 Q.getLocalEndLoc());
3388 break;
3389 }
Richard Trieude756fb2011-05-07 01:36:37 +00003390 // If the nested-name-specifier is an invalid type def, don't emit an
3391 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003392 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3393 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003394 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003395 << TL.getType() << SS.getRange();
3396 }
Douglas Gregor14454802011-02-25 02:25:35 +00003397 return NestedNameSpecifierLoc();
3398 }
Douglas Gregore16af532011-02-28 18:50:33 +00003399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
Douglas Gregore16af532011-02-28 18:50:33 +00003401 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003402 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003403 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor14454802011-02-25 02:25:35 +00003406 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003407 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003408 !getDerived().AlwaysRebuild())
3409 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
3411 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003412 // nested-name-specifier, do so.
3413 if (SS.location_size() == NNS.getDataLength() &&
3414 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3415 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3416
3417 // Allocate new nested-name-specifier location information.
3418 return SS.getWithLocInContext(SemaRef.Context);
3419}
3420
3421template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003422DeclarationNameInfo
3423TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003424::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003425 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003426 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003427 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003428
3429 switch (Name.getNameKind()) {
3430 case DeclarationName::Identifier:
3431 case DeclarationName::ObjCZeroArgSelector:
3432 case DeclarationName::ObjCOneArgSelector:
3433 case DeclarationName::ObjCMultiArgSelector:
3434 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003435 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003436 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003437 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003438
Douglas Gregorf816bd72009-09-03 22:13:48 +00003439 case DeclarationName::CXXConstructorName:
3440 case DeclarationName::CXXDestructorName:
3441 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003442 TypeSourceInfo *NewTInfo;
3443 CanQualType NewCanTy;
3444 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003445 NewTInfo = getDerived().TransformType(OldTInfo);
3446 if (!NewTInfo)
3447 return DeclarationNameInfo();
3448 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003449 }
3450 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003451 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003452 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003453 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003454 if (NewT.isNull())
3455 return DeclarationNameInfo();
3456 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3457 }
Mike Stump11289f42009-09-09 15:08:12 +00003458
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003459 DeclarationName NewName
3460 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3461 NewCanTy);
3462 DeclarationNameInfo NewNameInfo(NameInfo);
3463 NewNameInfo.setName(NewName);
3464 NewNameInfo.setNamedTypeInfo(NewTInfo);
3465 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003466 }
Mike Stump11289f42009-09-09 15:08:12 +00003467 }
3468
David Blaikie83d382b2011-09-23 05:06:16 +00003469 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003470}
3471
3472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003473TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003474TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3475 TemplateName Name,
3476 SourceLocation NameLoc,
3477 QualType ObjectType,
3478 NamedDecl *FirstQualifierInScope) {
3479 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3480 TemplateDecl *Template = QTN->getTemplateDecl();
3481 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
Douglas Gregor9db53502011-03-02 18:07:45 +00003483 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003484 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003485 Template));
3486 if (!TransTemplate)
3487 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003488
Douglas Gregor9db53502011-03-02 18:07:45 +00003489 if (!getDerived().AlwaysRebuild() &&
3490 SS.getScopeRep() == QTN->getQualifier() &&
3491 TransTemplate == Template)
3492 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregor9db53502011-03-02 18:07:45 +00003494 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3495 TransTemplate);
3496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
Douglas Gregor9db53502011-03-02 18:07:45 +00003498 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3499 if (SS.getScopeRep()) {
3500 // These apply to the scope specifier, not the template.
3501 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003502 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003503 }
3504
Douglas Gregor9db53502011-03-02 18:07:45 +00003505 if (!getDerived().AlwaysRebuild() &&
3506 SS.getScopeRep() == DTN->getQualifier() &&
3507 ObjectType.isNull())
3508 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregor9db53502011-03-02 18:07:45 +00003510 if (DTN->isIdentifier()) {
3511 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003512 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003513 NameLoc,
3514 ObjectType,
3515 FirstQualifierInScope);
3516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor9db53502011-03-02 18:07:45 +00003518 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3519 ObjectType);
3520 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor9db53502011-03-02 18:07:45 +00003522 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3523 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003525 Template));
3526 if (!TransTemplate)
3527 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
Douglas Gregor9db53502011-03-02 18:07:45 +00003529 if (!getDerived().AlwaysRebuild() &&
3530 TransTemplate == Template)
3531 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
Douglas Gregor9db53502011-03-02 18:07:45 +00003533 return TemplateName(TransTemplate);
3534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor9db53502011-03-02 18:07:45 +00003536 if (SubstTemplateTemplateParmPackStorage *SubstPack
3537 = Name.getAsSubstTemplateTemplateParmPack()) {
3538 TemplateTemplateParmDecl *TransParam
3539 = cast_or_null<TemplateTemplateParmDecl>(
3540 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3541 if (!TransParam)
3542 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregor9db53502011-03-02 18:07:45 +00003544 if (!getDerived().AlwaysRebuild() &&
3545 TransParam == SubstPack->getParameterPack())
3546 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
3548 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003549 SubstPack->getArgumentPack());
3550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregor9db53502011-03-02 18:07:45 +00003552 // These should be getting filtered out before they reach the AST.
3553 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003554}
3555
3556template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003557void TreeTransform<Derived>::InventTemplateArgumentLoc(
3558 const TemplateArgument &Arg,
3559 TemplateArgumentLoc &Output) {
3560 SourceLocation Loc = getDerived().getBaseLocation();
3561 switch (Arg.getKind()) {
3562 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003563 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003564 break;
3565
3566 case TemplateArgument::Type:
3567 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003568 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
John McCall0ad16662009-10-29 08:12:44 +00003570 break;
3571
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003572 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003573 case TemplateArgument::TemplateExpansion: {
3574 NestedNameSpecifierLocBuilder Builder;
3575 TemplateName Template = Arg.getAsTemplate();
3576 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3577 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3578 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3579 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor9d802122011-03-02 17:09:35 +00003581 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003582 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003583 Builder.getWithLocInContext(SemaRef.Context),
3584 Loc);
3585 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003586 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003587 Builder.getWithLocInContext(SemaRef.Context),
3588 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003590 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003591 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003592
John McCall0ad16662009-10-29 08:12:44 +00003593 case TemplateArgument::Expression:
3594 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3595 break;
3596
3597 case TemplateArgument::Declaration:
3598 case TemplateArgument::Integral:
3599 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003600 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003601 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003602 break;
3603 }
3604}
3605
3606template<typename Derived>
3607bool TreeTransform<Derived>::TransformTemplateArgument(
3608 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003609 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003610 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003611 switch (Arg.getKind()) {
3612 case TemplateArgument::Null:
3613 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003614 case TemplateArgument::Pack:
3615 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003616 case TemplateArgument::NullPtr:
3617 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003618
Douglas Gregore922c772009-08-04 22:27:00 +00003619 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003620 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003621 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003622 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003623
3624 DI = getDerived().TransformType(DI);
3625 if (!DI) return true;
3626
3627 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3628 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003629 }
Mike Stump11289f42009-09-09 15:08:12 +00003630
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003631 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003632 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3633 if (QualifierLoc) {
3634 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3635 if (!QualifierLoc)
3636 return true;
3637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregordf846d12011-03-02 18:46:51 +00003639 CXXScopeSpec SS;
3640 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003641 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003642 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3643 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003644 if (Template.isNull())
3645 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor9d802122011-03-02 17:09:35 +00003647 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003648 Input.getTemplateNameLoc());
3649 return false;
3650 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003651
3652 case TemplateArgument::TemplateExpansion:
3653 llvm_unreachable("Caller should expand pack expansions");
3654
Douglas Gregore922c772009-08-04 22:27:00 +00003655 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003656 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003657 EnterExpressionEvaluationContext Unevaluated(
3658 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003659
John McCall0ad16662009-10-29 08:12:44 +00003660 Expr *InputExpr = Input.getSourceExpression();
3661 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3662
Chris Lattnercdb591a2011-04-25 20:37:58 +00003663 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003664 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003665 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003666 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003667 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003668 }
Douglas Gregore922c772009-08-04 22:27:00 +00003669 }
Mike Stump11289f42009-09-09 15:08:12 +00003670
Douglas Gregore922c772009-08-04 22:27:00 +00003671 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003672 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003673}
3674
Douglas Gregorfe921a72010-12-20 23:36:19 +00003675/// \brief Iterator adaptor that invents template argument location information
3676/// for each of the template arguments in its underlying iterator.
3677template<typename Derived, typename InputIterator>
3678class TemplateArgumentLocInventIterator {
3679 TreeTransform<Derived> &Self;
3680 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003681
Douglas Gregorfe921a72010-12-20 23:36:19 +00003682public:
3683 typedef TemplateArgumentLoc value_type;
3684 typedef TemplateArgumentLoc reference;
3685 typedef typename std::iterator_traits<InputIterator>::difference_type
3686 difference_type;
3687 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregorfe921a72010-12-20 23:36:19 +00003689 class pointer {
3690 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregorfe921a72010-12-20 23:36:19 +00003692 public:
3693 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregorfe921a72010-12-20 23:36:19 +00003695 const TemplateArgumentLoc *operator->() const { return &Arg; }
3696 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003697
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003698 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003699
Douglas Gregorfe921a72010-12-20 23:36:19 +00003700 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3701 InputIterator Iter)
3702 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003703
Douglas Gregorfe921a72010-12-20 23:36:19 +00003704 TemplateArgumentLocInventIterator &operator++() {
3705 ++Iter;
3706 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003708
Douglas Gregorfe921a72010-12-20 23:36:19 +00003709 TemplateArgumentLocInventIterator operator++(int) {
3710 TemplateArgumentLocInventIterator Old(*this);
3711 ++(*this);
3712 return Old;
3713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003714
Douglas Gregorfe921a72010-12-20 23:36:19 +00003715 reference operator*() const {
3716 TemplateArgumentLoc Result;
3717 Self.InventTemplateArgumentLoc(*Iter, Result);
3718 return Result;
3719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregorfe921a72010-12-20 23:36:19 +00003721 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003722
Douglas Gregorfe921a72010-12-20 23:36:19 +00003723 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3724 const TemplateArgumentLocInventIterator &Y) {
3725 return X.Iter == Y.Iter;
3726 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003727
Douglas Gregorfe921a72010-12-20 23:36:19 +00003728 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3729 const TemplateArgumentLocInventIterator &Y) {
3730 return X.Iter != Y.Iter;
3731 }
3732};
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Douglas Gregor42cafa82010-12-20 17:42:22 +00003734template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003735template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003736bool TreeTransform<Derived>::TransformTemplateArguments(
3737 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3738 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003739 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003740 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003741 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003742
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003743 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3744 // Unpack argument packs, which we translate them into separate
3745 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003746 // FIXME: We could do much better if we could guarantee that the
3747 // TemplateArgumentLocInfo for the pack expansion would be usable for
3748 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003749 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003750 TemplateArgument::pack_iterator>
3751 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003752 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003753 In.getArgument().pack_begin()),
3754 PackLocIterator(*this,
3755 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003756 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003757 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003759 continue;
3760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003762 if (In.getArgument().isPackExpansion()) {
3763 // We have a pack expansion, for which we will be substituting into
3764 // the pattern.
3765 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003766 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003767 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003768 = getSema().getTemplateArgumentPackExpansionPattern(
3769 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003770
Chris Lattner01cf8db2011-07-20 06:58:45 +00003771 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003772 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3773 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003775 // Determine whether the set of unexpanded parameter packs can and should
3776 // be expanded.
3777 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003778 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003779 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003780 if (getDerived().TryExpandParameterPacks(Ellipsis,
3781 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003782 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003783 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003784 RetainExpansion,
3785 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003786 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003787
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003788 if (!Expand) {
3789 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003790 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003791 // expansion.
3792 TemplateArgumentLoc OutPattern;
3793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003794 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003795 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003796
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003797 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3798 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003799 if (Out.getArgument().isNull())
3800 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003802 Outputs.addArgument(Out);
3803 continue;
3804 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003805
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003806 // The transform has determined that we should perform an elementwise
3807 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003808 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003809 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3810
Richard Smithd784e682015-09-23 21:41:42 +00003811 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003812 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003814 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003815 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3816 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003817 if (Out.getArgument().isNull())
3818 return true;
3819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003821 Outputs.addArgument(Out);
3822 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003823
Douglas Gregor48d24112011-01-10 20:53:55 +00003824 // If we're supposed to retain a pack expansion, do so by temporarily
3825 // forgetting the partially-substituted parameter pack.
3826 if (RetainExpansion) {
3827 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003828
Richard Smithd784e682015-09-23 21:41:42 +00003829 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003830 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003831
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003832 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3833 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003834 if (Out.getArgument().isNull())
3835 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Douglas Gregor48d24112011-01-10 20:53:55 +00003837 Outputs.addArgument(Out);
3838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003840 continue;
3841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003842
3843 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003844 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003845 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846
Douglas Gregor42cafa82010-12-20 17:42:22 +00003847 Outputs.addArgument(Out);
3848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003849
Douglas Gregor42cafa82010-12-20 17:42:22 +00003850 return false;
3851
3852}
3853
Douglas Gregord6ff3322009-08-04 16:50:30 +00003854//===----------------------------------------------------------------------===//
3855// Type transformation
3856//===----------------------------------------------------------------------===//
3857
3858template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003859QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003860 if (getDerived().AlreadyTransformed(T))
3861 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003862
John McCall550e0c22009-10-21 00:40:46 +00003863 // Temporary workaround. All of these transformations should
3864 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003865 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3866 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
John McCall31f82722010-11-12 08:19:04 +00003868 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003869
John McCall550e0c22009-10-21 00:40:46 +00003870 if (!NewDI)
3871 return QualType();
3872
3873 return NewDI->getType();
3874}
3875
3876template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003877TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003878 // Refine the base location to the type's location.
3879 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3880 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003881 if (getDerived().AlreadyTransformed(DI->getType()))
3882 return DI;
3883
3884 TypeLocBuilder TLB;
3885
3886 TypeLoc TL = DI->getTypeLoc();
3887 TLB.reserve(TL.getFullDataSize());
3888
John McCall31f82722010-11-12 08:19:04 +00003889 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003890 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003891 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003892
John McCallbcd03502009-12-07 02:54:59 +00003893 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003894}
3895
3896template<typename Derived>
3897QualType
John McCall31f82722010-11-12 08:19:04 +00003898TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003899 switch (T.getTypeLocClass()) {
3900#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003901#define TYPELOC(CLASS, PARENT) \
3902 case TypeLoc::CLASS: \
3903 return getDerived().Transform##CLASS##Type(TLB, \
3904 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003905#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003906 }
Mike Stump11289f42009-09-09 15:08:12 +00003907
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003908 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003909}
3910
3911/// FIXME: By default, this routine adds type qualifiers only to types
3912/// that can have qualifiers, and silently suppresses those qualifiers
3913/// that are not permitted (e.g., qualifiers on reference or function
3914/// types). This is the right thing for template instantiation, but
3915/// probably not for other clients.
3916template<typename Derived>
3917QualType
3918TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003919 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003920 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003921
John McCall31f82722010-11-12 08:19:04 +00003922 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003923 if (Result.isNull())
3924 return QualType();
3925
3926 // Silently suppress qualifiers if the result type can't be qualified.
3927 // FIXME: this is the right thing for template instantiation, but
3928 // probably not for other clients.
3929 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003931
John McCall31168b02011-06-15 23:02:42 +00003932 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003933 // resulting type.
3934 if (Quals.hasObjCLifetime()) {
3935 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3936 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003937 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003938 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003939 // A lifetime qualifier applied to a substituted template parameter
3940 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003941 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003942 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003943 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3944 QualType Replacement = SubstTypeParam->getReplacementType();
3945 Qualifiers Qs = Replacement.getQualifiers();
3946 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003947 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003948 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3949 Qs);
3950 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003951 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003952 Replacement);
3953 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003954 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3955 // 'auto' types behave the same way as template parameters.
3956 QualType Deduced = AutoTy->getDeducedType();
3957 Qualifiers Qs = Deduced.getQualifiers();
3958 Qs.removeObjCLifetime();
3959 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3960 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003961 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003962 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003963 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003964 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003965 // Otherwise, complain about the addition of a qualifier to an
3966 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003967 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003968 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003969 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
Douglas Gregore46db902011-06-17 22:11:49 +00003971 Quals.removeObjCLifetime();
3972 }
3973 }
3974 }
John McCallcb0f89a2010-06-05 06:41:15 +00003975 if (!Quals.empty()) {
3976 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003977 // BuildQualifiedType might not add qualifiers if they are invalid.
3978 if (Result.hasLocalQualifiers())
3979 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003980 // No location information to preserve.
3981 }
John McCall550e0c22009-10-21 00:40:46 +00003982
3983 return Result;
3984}
3985
Douglas Gregor14454802011-02-25 02:25:35 +00003986template<typename Derived>
3987TypeLoc
3988TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3989 QualType ObjectType,
3990 NamedDecl *UnqualLookup,
3991 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003992 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003993 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003995 TypeSourceInfo *TSI =
3996 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3997 if (TSI)
3998 return TSI->getTypeLoc();
3999 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004000}
4001
Douglas Gregor579c15f2011-03-02 18:32:08 +00004002template<typename Derived>
4003TypeSourceInfo *
4004TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4005 QualType ObjectType,
4006 NamedDecl *UnqualLookup,
4007 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004008 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004009 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004010
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004011 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4012 UnqualLookup, SS);
4013}
4014
4015template <typename Derived>
4016TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4017 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4018 CXXScopeSpec &SS) {
4019 QualType T = TL.getType();
4020 assert(!getDerived().AlreadyTransformed(T));
4021
Douglas Gregor579c15f2011-03-02 18:32:08 +00004022 TypeLocBuilder TLB;
4023 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004024
Douglas Gregor579c15f2011-03-02 18:32:08 +00004025 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004026 TemplateSpecializationTypeLoc SpecTL =
4027 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004028
Douglas Gregor579c15f2011-03-02 18:32:08 +00004029 TemplateName Template
4030 = getDerived().TransformTemplateName(SS,
4031 SpecTL.getTypePtr()->getTemplateName(),
4032 SpecTL.getTemplateNameLoc(),
4033 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004034 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004035 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004036
4037 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004038 Template);
4039 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004040 DependentTemplateSpecializationTypeLoc SpecTL =
4041 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004042
Douglas Gregor579c15f2011-03-02 18:32:08 +00004043 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004044 = getDerived().RebuildTemplateName(SS,
4045 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004046 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004047 ObjectType, UnqualLookup);
4048 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004049 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004050
4051 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004052 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004053 Template,
4054 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004055 } else {
4056 // Nothing special needs to be done for these.
4057 Result = getDerived().TransformType(TLB, TL);
4058 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004059
4060 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004061 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Douglas Gregor579c15f2011-03-02 18:32:08 +00004063 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4064}
4065
John McCall550e0c22009-10-21 00:40:46 +00004066template <class TyLoc> static inline
4067QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4068 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4069 NewT.setNameLoc(T.getNameLoc());
4070 return T.getType();
4071}
4072
John McCall550e0c22009-10-21 00:40:46 +00004073template<typename Derived>
4074QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004075 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004076 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4077 NewT.setBuiltinLoc(T.getBuiltinLoc());
4078 if (T.needsExtraLocalData())
4079 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4080 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081}
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004084QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004086 // FIXME: recurse?
4087 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
Reid Kleckner0503a872013-12-05 01:23:43 +00004090template <typename Derived>
4091QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4092 AdjustedTypeLoc TL) {
4093 // Adjustments applied during transformation are handled elsewhere.
4094 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4095}
4096
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004098QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4099 DecayedTypeLoc TL) {
4100 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4101 if (OriginalType.isNull())
4102 return QualType();
4103
4104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() ||
4106 OriginalType != TL.getOriginalLoc().getType())
4107 Result = SemaRef.Context.getDecayedType(OriginalType);
4108 TLB.push<DecayedTypeLoc>(Result);
4109 // Nothing to set for DecayedTypeLoc.
4110 return Result;
4111}
4112
4113template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004114QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004115 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004116 QualType PointeeType
4117 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004118 if (PointeeType.isNull())
4119 return QualType();
4120
4121 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004122 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004123 // A dependent pointer type 'T *' has is being transformed such
4124 // that an Objective-C class type is being replaced for 'T'. The
4125 // resulting pointer type is an ObjCObjectPointerType, not a
4126 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004127 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
John McCall8b07ec22010-05-15 11:32:37 +00004129 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4130 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004131 return Result;
4132 }
John McCall31f82722010-11-12 08:19:04 +00004133
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004134 if (getDerived().AlwaysRebuild() ||
4135 PointeeType != TL.getPointeeLoc().getType()) {
4136 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4137 if (Result.isNull())
4138 return QualType();
4139 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004140
John McCall31168b02011-06-15 23:02:42 +00004141 // Objective-C ARC can add lifetime qualifiers to the type that we're
4142 // pointing to.
4143 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004144
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004145 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4146 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004147 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148}
Mike Stump11289f42009-09-09 15:08:12 +00004149
4150template<typename Derived>
4151QualType
John McCall550e0c22009-10-21 00:40:46 +00004152TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004153 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004154 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004155 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4156 if (PointeeType.isNull())
4157 return QualType();
4158
4159 QualType Result = TL.getType();
4160 if (getDerived().AlwaysRebuild() ||
4161 PointeeType != TL.getPointeeLoc().getType()) {
4162 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004163 TL.getSigilLoc());
4164 if (Result.isNull())
4165 return QualType();
4166 }
4167
Douglas Gregor049211a2010-04-22 16:50:51 +00004168 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004169 NewT.setSigilLoc(TL.getSigilLoc());
4170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171}
4172
John McCall70dd5f62009-10-30 00:06:24 +00004173/// Transforms a reference type. Note that somewhat paradoxically we
4174/// don't care whether the type itself is an l-value type or an r-value
4175/// type; we only care if the type was *written* as an l-value type
4176/// or an r-value type.
4177template<typename Derived>
4178QualType
4179TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004180 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004181 const ReferenceType *T = TL.getTypePtr();
4182
4183 // Note that this works with the pointee-as-written.
4184 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4185 if (PointeeType.isNull())
4186 return QualType();
4187
4188 QualType Result = TL.getType();
4189 if (getDerived().AlwaysRebuild() ||
4190 PointeeType != T->getPointeeTypeAsWritten()) {
4191 Result = getDerived().RebuildReferenceType(PointeeType,
4192 T->isSpelledAsLValue(),
4193 TL.getSigilLoc());
4194 if (Result.isNull())
4195 return QualType();
4196 }
4197
John McCall31168b02011-06-15 23:02:42 +00004198 // Objective-C ARC can add lifetime qualifiers to the type that we're
4199 // referring to.
4200 TLB.TypeWasModifiedSafely(
4201 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4202
John McCall70dd5f62009-10-30 00:06:24 +00004203 // r-value references can be rebuilt as l-value references.
4204 ReferenceTypeLoc NewTL;
4205 if (isa<LValueReferenceType>(Result))
4206 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4207 else
4208 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4209 NewTL.setSigilLoc(TL.getSigilLoc());
4210
4211 return Result;
4212}
4213
Mike Stump11289f42009-09-09 15:08:12 +00004214template<typename Derived>
4215QualType
John McCall550e0c22009-10-21 00:40:46 +00004216TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004217 LValueReferenceTypeLoc TL) {
4218 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219}
4220
Mike Stump11289f42009-09-09 15:08:12 +00004221template<typename Derived>
4222QualType
John McCall550e0c22009-10-21 00:40:46 +00004223TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004224 RValueReferenceTypeLoc TL) {
4225 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004226}
Mike Stump11289f42009-09-09 15:08:12 +00004227
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004229QualType
John McCall550e0c22009-10-21 00:40:46 +00004230TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004232 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233 if (PointeeType.isNull())
4234 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004235
Abramo Bagnara509357842011-03-05 14:42:21 +00004236 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004237 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004238 if (OldClsTInfo) {
4239 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4240 if (!NewClsTInfo)
4241 return QualType();
4242 }
4243
4244 const MemberPointerType *T = TL.getTypePtr();
4245 QualType OldClsType = QualType(T->getClass(), 0);
4246 QualType NewClsType;
4247 if (NewClsTInfo)
4248 NewClsType = NewClsTInfo->getType();
4249 else {
4250 NewClsType = getDerived().TransformType(OldClsType);
4251 if (NewClsType.isNull())
4252 return QualType();
4253 }
Mike Stump11289f42009-09-09 15:08:12 +00004254
John McCall550e0c22009-10-21 00:40:46 +00004255 QualType Result = TL.getType();
4256 if (getDerived().AlwaysRebuild() ||
4257 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004258 NewClsType != OldClsType) {
4259 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004260 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004261 if (Result.isNull())
4262 return QualType();
4263 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004264
Reid Kleckner0503a872013-12-05 01:23:43 +00004265 // If we had to adjust the pointee type when building a member pointer, make
4266 // sure to push TypeLoc info for it.
4267 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4268 if (MPT && PointeeType != MPT->getPointeeType()) {
4269 assert(isa<AdjustedType>(MPT->getPointeeType()));
4270 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4271 }
4272
John McCall550e0c22009-10-21 00:40:46 +00004273 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4274 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004275 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004276
4277 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004278}
4279
Mike Stump11289f42009-09-09 15:08:12 +00004280template<typename Derived>
4281QualType
John McCall550e0c22009-10-21 00:40:46 +00004282TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004283 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004284 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004285 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286 if (ElementType.isNull())
4287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004288
John McCall550e0c22009-10-21 00:40:46 +00004289 QualType Result = TL.getType();
4290 if (getDerived().AlwaysRebuild() ||
4291 ElementType != T->getElementType()) {
4292 Result = getDerived().RebuildConstantArrayType(ElementType,
4293 T->getSizeModifier(),
4294 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004295 T->getIndexTypeCVRQualifiers(),
4296 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004297 if (Result.isNull())
4298 return QualType();
4299 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004300
4301 // We might have either a ConstantArrayType or a VariableArrayType now:
4302 // a ConstantArrayType is allowed to have an element type which is a
4303 // VariableArrayType if the type is dependent. Fortunately, all array
4304 // types have the same location layout.
4305 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004306 NewTL.setLBracketLoc(TL.getLBracketLoc());
4307 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004308
John McCall550e0c22009-10-21 00:40:46 +00004309 Expr *Size = TL.getSizeExpr();
4310 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004311 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4312 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004313 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4314 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004315 }
4316 NewTL.setSizeExpr(Size);
4317
4318 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004319}
Mike Stump11289f42009-09-09 15:08:12 +00004320
Douglas Gregord6ff3322009-08-04 16:50:30 +00004321template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004322QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004323 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004324 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004325 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004326 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004327 if (ElementType.isNull())
4328 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004329
John McCall550e0c22009-10-21 00:40:46 +00004330 QualType Result = TL.getType();
4331 if (getDerived().AlwaysRebuild() ||
4332 ElementType != T->getElementType()) {
4333 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004334 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004335 T->getIndexTypeCVRQualifiers(),
4336 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004337 if (Result.isNull())
4338 return QualType();
4339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004340
John McCall550e0c22009-10-21 00:40:46 +00004341 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4342 NewTL.setLBracketLoc(TL.getLBracketLoc());
4343 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004344 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004345
4346 return Result;
4347}
4348
4349template<typename Derived>
4350QualType
4351TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004352 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004353 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004354 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4355 if (ElementType.isNull())
4356 return QualType();
4357
John McCalldadc5752010-08-24 06:29:42 +00004358 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004359 = getDerived().TransformExpr(T->getSizeExpr());
4360 if (SizeResult.isInvalid())
4361 return QualType();
4362
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004363 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004364
4365 QualType Result = TL.getType();
4366 if (getDerived().AlwaysRebuild() ||
4367 ElementType != T->getElementType() ||
4368 Size != T->getSizeExpr()) {
4369 Result = getDerived().RebuildVariableArrayType(ElementType,
4370 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004371 Size,
John McCall550e0c22009-10-21 00:40:46 +00004372 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004373 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004374 if (Result.isNull())
4375 return QualType();
4376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Serge Pavlov774c6d02014-02-06 03:49:11 +00004378 // We might have constant size array now, but fortunately it has the same
4379 // location layout.
4380 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004381 NewTL.setLBracketLoc(TL.getLBracketLoc());
4382 NewTL.setRBracketLoc(TL.getRBracketLoc());
4383 NewTL.setSizeExpr(Size);
4384
4385 return Result;
4386}
4387
4388template<typename Derived>
4389QualType
4390TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004391 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004392 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004393 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4394 if (ElementType.isNull())
4395 return QualType();
4396
Richard Smith764d2fe2011-12-20 02:08:33 +00004397 // Array bounds are constant expressions.
4398 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4399 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004400
John McCall33ddac02011-01-19 10:06:00 +00004401 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4402 Expr *origSize = TL.getSizeExpr();
4403 if (!origSize) origSize = T->getSizeExpr();
4404
4405 ExprResult sizeResult
4406 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004407 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004408 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004409 return QualType();
4410
John McCall33ddac02011-01-19 10:06:00 +00004411 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004412
4413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
4415 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004416 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004417 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4418 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004419 size,
John McCall550e0c22009-10-21 00:40:46 +00004420 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004421 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004422 if (Result.isNull())
4423 return QualType();
4424 }
John McCall550e0c22009-10-21 00:40:46 +00004425
4426 // We might have any sort of array type now, but fortunately they
4427 // all have the same location layout.
4428 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4429 NewTL.setLBracketLoc(TL.getLBracketLoc());
4430 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004431 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004432
4433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
4436template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004437QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004438 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004439 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004440 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004441
4442 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004443 QualType ElementType = getDerived().TransformType(T->getElementType());
4444 if (ElementType.isNull())
4445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004446
Richard Smith764d2fe2011-12-20 02:08:33 +00004447 // Vector sizes are constant expressions.
4448 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4449 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004450
John McCalldadc5752010-08-24 06:29:42 +00004451 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004452 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004453 if (Size.isInvalid())
4454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004455
John McCall550e0c22009-10-21 00:40:46 +00004456 QualType Result = TL.getType();
4457 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004458 ElementType != T->getElementType() ||
4459 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004460 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004461 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004463 if (Result.isNull())
4464 return QualType();
4465 }
John McCall550e0c22009-10-21 00:40:46 +00004466
4467 // Result might be dependent or not.
4468 if (isa<DependentSizedExtVectorType>(Result)) {
4469 DependentSizedExtVectorTypeLoc NewTL
4470 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4471 NewTL.setNameLoc(TL.getNameLoc());
4472 } else {
4473 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4474 NewTL.setNameLoc(TL.getNameLoc());
4475 }
4476
4477 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004478}
Mike Stump11289f42009-09-09 15:08:12 +00004479
4480template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004481QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004482 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004483 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004484 QualType ElementType = getDerived().TransformType(T->getElementType());
4485 if (ElementType.isNull())
4486 return QualType();
4487
John McCall550e0c22009-10-21 00:40:46 +00004488 QualType Result = TL.getType();
4489 if (getDerived().AlwaysRebuild() ||
4490 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004491 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004492 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004493 if (Result.isNull())
4494 return QualType();
4495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004496
John McCall550e0c22009-10-21 00:40:46 +00004497 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4498 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCall550e0c22009-10-21 00:40:46 +00004500 return Result;
4501}
4502
4503template<typename Derived>
4504QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004505 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004506 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004507 QualType ElementType = getDerived().TransformType(T->getElementType());
4508 if (ElementType.isNull())
4509 return QualType();
4510
4511 QualType Result = TL.getType();
4512 if (getDerived().AlwaysRebuild() ||
4513 ElementType != T->getElementType()) {
4514 Result = getDerived().RebuildExtVectorType(ElementType,
4515 T->getNumElements(),
4516 /*FIXME*/ SourceLocation());
4517 if (Result.isNull())
4518 return QualType();
4519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004520
John McCall550e0c22009-10-21 00:40:46 +00004521 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4522 NewTL.setNameLoc(TL.getNameLoc());
4523
4524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004525}
Mike Stump11289f42009-09-09 15:08:12 +00004526
David Blaikie05785d12013-02-20 22:23:23 +00004527template <typename Derived>
4528ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4529 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4530 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004531 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004532 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004533
Douglas Gregor715e4612011-01-14 22:40:04 +00004534 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004535 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004536 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004537 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004538 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004539
Douglas Gregor715e4612011-01-14 22:40:04 +00004540 TypeLocBuilder TLB;
4541 TypeLoc NewTL = OldDI->getTypeLoc();
4542 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004543
4544 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004545 OldExpansionTL.getPatternLoc());
4546 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004547 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004548
4549 Result = RebuildPackExpansionType(Result,
4550 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004551 OldExpansionTL.getEllipsisLoc(),
4552 NumExpansions);
4553 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004554 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004555
Douglas Gregor715e4612011-01-14 22:40:04 +00004556 PackExpansionTypeLoc NewExpansionTL
4557 = TLB.push<PackExpansionTypeLoc>(Result);
4558 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4559 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4560 } else
4561 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004562 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004563 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004564
John McCall8fb0d9d2011-05-01 22:35:37 +00004565 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004566 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004567
4568 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4569 OldParm->getDeclContext(),
4570 OldParm->getInnerLocStart(),
4571 OldParm->getLocation(),
4572 OldParm->getIdentifier(),
4573 NewDI->getType(),
4574 NewDI,
4575 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004576 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004577 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4578 OldParm->getFunctionScopeIndex() + indexAdjustment);
4579 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004580}
4581
4582template<typename Derived>
4583bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004584 TransformFunctionTypeParams(SourceLocation Loc,
4585 ParmVarDecl **Params, unsigned NumParams,
4586 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004587 SmallVectorImpl<QualType> &OutParamTypes,
4588 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004589 int indexAdjustment = 0;
4590
Douglas Gregordd472162011-01-07 00:20:55 +00004591 for (unsigned i = 0; i != NumParams; ++i) {
4592 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004593 assert(OldParm->getFunctionScopeIndex() == i);
4594
David Blaikie05785d12013-02-20 22:23:23 +00004595 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004596 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004597 if (OldParm->isParameterPack()) {
4598 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004599 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004600
Douglas Gregor5499af42011-01-05 23:12:31 +00004601 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004602 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004603 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004604 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4605 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004606 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4607
Douglas Gregor5499af42011-01-05 23:12:31 +00004608 // Determine whether we should expand the parameter packs.
4609 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004610 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004611 Optional<unsigned> OrigNumExpansions =
4612 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004613 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004614 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4615 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004616 Unexpanded,
4617 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004618 RetainExpansion,
4619 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004620 return true;
4621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004622
Douglas Gregor5499af42011-01-05 23:12:31 +00004623 if (ShouldExpand) {
4624 // Expand the function parameter pack into multiple, separate
4625 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004626 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004627 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004628 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004629 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004630 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004631 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004632 OrigNumExpansions,
4633 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004634 if (!NewParm)
4635 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004636
Douglas Gregordd472162011-01-07 00:20:55 +00004637 OutParamTypes.push_back(NewParm->getType());
4638 if (PVars)
4639 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004640 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004641
4642 // If we're supposed to retain a pack expansion, do so by temporarily
4643 // forgetting the partially-substituted parameter pack.
4644 if (RetainExpansion) {
4645 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004646 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004647 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004648 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004649 OrigNumExpansions,
4650 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004651 if (!NewParm)
4652 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004653
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004654 OutParamTypes.push_back(NewParm->getType());
4655 if (PVars)
4656 PVars->push_back(NewParm);
4657 }
4658
John McCall8fb0d9d2011-05-01 22:35:37 +00004659 // The next parameter should have the same adjustment as the
4660 // last thing we pushed, but we post-incremented indexAdjustment
4661 // on every push. Also, if we push nothing, the adjustment should
4662 // go down by one.
4663 indexAdjustment--;
4664
Douglas Gregor5499af42011-01-05 23:12:31 +00004665 // We're done with the pack expansion.
4666 continue;
4667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004668
4669 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004670 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004671 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4672 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004673 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004674 NumExpansions,
4675 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004676 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004677 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004678 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004679 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004680
John McCall58f10c32010-03-11 09:03:00 +00004681 if (!NewParm)
4682 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004683
Douglas Gregordd472162011-01-07 00:20:55 +00004684 OutParamTypes.push_back(NewParm->getType());
4685 if (PVars)
4686 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004687 continue;
4688 }
John McCall58f10c32010-03-11 09:03:00 +00004689
4690 // Deal with the possibility that we don't have a parameter
4691 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004692 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004693 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004694 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004695 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004696 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004697 = dyn_cast<PackExpansionType>(OldType)) {
4698 // We have a function parameter pack that may need to be expanded.
4699 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004700 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004701 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004702
Douglas Gregor5499af42011-01-05 23:12:31 +00004703 // Determine whether we should expand the parameter packs.
4704 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004705 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004706 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004707 Unexpanded,
4708 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004709 RetainExpansion,
4710 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004711 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004713
Douglas Gregor5499af42011-01-05 23:12:31 +00004714 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004715 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004716 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004717 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004718 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4719 QualType NewType = getDerived().TransformType(Pattern);
4720 if (NewType.isNull())
4721 return true;
John McCall58f10c32010-03-11 09:03:00 +00004722
Douglas Gregordd472162011-01-07 00:20:55 +00004723 OutParamTypes.push_back(NewType);
4724 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004725 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004727
Douglas Gregor5499af42011-01-05 23:12:31 +00004728 // We're done with the pack expansion.
4729 continue;
4730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004731
Douglas Gregor48d24112011-01-10 20:53:55 +00004732 // If we're supposed to retain a pack expansion, do so by temporarily
4733 // forgetting the partially-substituted parameter pack.
4734 if (RetainExpansion) {
4735 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4736 QualType NewType = getDerived().TransformType(Pattern);
4737 if (NewType.isNull())
4738 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004739
Douglas Gregor48d24112011-01-10 20:53:55 +00004740 OutParamTypes.push_back(NewType);
4741 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004742 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004743 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004744
Chad Rosier1dcde962012-08-08 18:46:20 +00004745 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004746 // expansion.
4747 OldType = Expansion->getPattern();
4748 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004749 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4750 NewType = getDerived().TransformType(OldType);
4751 } else {
4752 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004754
Douglas Gregor5499af42011-01-05 23:12:31 +00004755 if (NewType.isNull())
4756 return true;
4757
4758 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004759 NewType = getSema().Context.getPackExpansionType(NewType,
4760 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004761
Douglas Gregordd472162011-01-07 00:20:55 +00004762 OutParamTypes.push_back(NewType);
4763 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004764 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004765 }
4766
John McCall8fb0d9d2011-05-01 22:35:37 +00004767#ifndef NDEBUG
4768 if (PVars) {
4769 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4770 if (ParmVarDecl *parm = (*PVars)[i])
4771 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004772 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004773#endif
4774
4775 return false;
4776}
John McCall58f10c32010-03-11 09:03:00 +00004777
4778template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004779QualType
John McCall550e0c22009-10-21 00:40:46 +00004780TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004781 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004782 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004783 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004784 return getDerived().TransformFunctionProtoType(
4785 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004786 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4787 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4788 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004789 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004790}
4791
Richard Smith2e321552014-11-12 02:00:47 +00004792template<typename Derived> template<typename Fn>
4793QualType TreeTransform<Derived>::TransformFunctionProtoType(
4794 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4795 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004796 // Transform the parameters and return type.
4797 //
Richard Smithf623c962012-04-17 00:58:00 +00004798 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004799 // When the function has a trailing return type, we instantiate the
4800 // parameters before the return type, since the return type can then refer
4801 // to the parameters themselves (via decltype, sizeof, etc.).
4802 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004803 SmallVector<QualType, 4> ParamTypes;
4804 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004805 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004806
Douglas Gregor7fb25412010-10-01 18:44:50 +00004807 QualType ResultType;
4808
Richard Smith1226c602012-08-14 22:51:13 +00004809 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004810 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004811 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004812 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004813 return QualType();
4814
Douglas Gregor3024f072012-04-16 07:05:22 +00004815 {
4816 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004817 // If a declaration declares a member function or member function
4818 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004819 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004820 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004821 // declarator.
4822 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004823
Alp Toker42a16a62014-01-25 23:51:36 +00004824 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004825 if (ResultType.isNull())
4826 return QualType();
4827 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004828 }
4829 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004830 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004831 if (ResultType.isNull())
4832 return QualType();
4833
Alp Toker9cacbab2014-01-20 20:26:09 +00004834 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004835 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004836 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004837 return QualType();
4838 }
4839
Richard Smith2e321552014-11-12 02:00:47 +00004840 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4841
4842 bool EPIChanged = false;
4843 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4844 return QualType();
4845
4846 // FIXME: Need to transform ConsumedParameters for variadic template
4847 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004848
John McCall550e0c22009-10-21 00:40:46 +00004849 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004850 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004851 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004852 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004853 if (Result.isNull())
4854 return QualType();
4855 }
Mike Stump11289f42009-09-09 15:08:12 +00004856
John McCall550e0c22009-10-21 00:40:46 +00004857 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004858 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004859 NewTL.setLParenLoc(TL.getLParenLoc());
4860 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004861 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004862 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4863 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004864
4865 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004866}
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregord6ff3322009-08-04 16:50:30 +00004868template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004869bool TreeTransform<Derived>::TransformExceptionSpec(
4870 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4871 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4872 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4873
4874 // Instantiate a dynamic noexcept expression, if any.
4875 if (ESI.Type == EST_ComputedNoexcept) {
4876 EnterExpressionEvaluationContext Unevaluated(getSema(),
4877 Sema::ConstantEvaluated);
4878 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4879 if (NoexceptExpr.isInvalid())
4880 return true;
4881
4882 NoexceptExpr = getSema().CheckBooleanCondition(
4883 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4884 if (NoexceptExpr.isInvalid())
4885 return true;
4886
4887 if (!NoexceptExpr.get()->isValueDependent()) {
4888 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4889 NoexceptExpr.get(), nullptr,
4890 diag::err_noexcept_needs_constant_expression,
4891 /*AllowFold*/false);
4892 if (NoexceptExpr.isInvalid())
4893 return true;
4894 }
4895
4896 if (ESI.NoexceptExpr != NoexceptExpr.get())
4897 Changed = true;
4898 ESI.NoexceptExpr = NoexceptExpr.get();
4899 }
4900
4901 if (ESI.Type != EST_Dynamic)
4902 return false;
4903
4904 // Instantiate a dynamic exception specification's type.
4905 for (QualType T : ESI.Exceptions) {
4906 if (const PackExpansionType *PackExpansion =
4907 T->getAs<PackExpansionType>()) {
4908 Changed = true;
4909
4910 // We have a pack expansion. Instantiate it.
4911 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4912 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4913 Unexpanded);
4914 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4915
4916 // Determine whether the set of unexpanded parameter packs can and
4917 // should
4918 // be expanded.
4919 bool Expand = false;
4920 bool RetainExpansion = false;
4921 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4922 // FIXME: Track the location of the ellipsis (and track source location
4923 // information for the types in the exception specification in general).
4924 if (getDerived().TryExpandParameterPacks(
4925 Loc, SourceRange(), Unexpanded, Expand,
4926 RetainExpansion, NumExpansions))
4927 return true;
4928
4929 if (!Expand) {
4930 // We can't expand this pack expansion into separate arguments yet;
4931 // just substitute into the pattern and create a new pack expansion
4932 // type.
4933 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4934 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4935 if (U.isNull())
4936 return true;
4937
4938 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4939 Exceptions.push_back(U);
4940 continue;
4941 }
4942
4943 // Substitute into the pack expansion pattern for each slice of the
4944 // pack.
4945 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4946 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4947
4948 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4949 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4950 return true;
4951
4952 Exceptions.push_back(U);
4953 }
4954 } else {
4955 QualType U = getDerived().TransformType(T);
4956 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4957 return true;
4958 if (T != U)
4959 Changed = true;
4960
4961 Exceptions.push_back(U);
4962 }
4963 }
4964
4965 ESI.Exceptions = Exceptions;
4966 return false;
4967}
4968
4969template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004970QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004971 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004972 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004973 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004974 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004975 if (ResultType.isNull())
4976 return QualType();
4977
4978 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004979 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004980 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4981
4982 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004983 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004984 NewTL.setLParenLoc(TL.getLParenLoc());
4985 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004986 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004987
4988 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004989}
Mike Stump11289f42009-09-09 15:08:12 +00004990
John McCallb96ec562009-12-04 22:46:56 +00004991template<typename Derived> QualType
4992TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004993 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004994 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004995 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004996 if (!D)
4997 return QualType();
4998
4999 QualType Result = TL.getType();
5000 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5001 Result = getDerived().RebuildUnresolvedUsingType(D);
5002 if (Result.isNull())
5003 return QualType();
5004 }
5005
5006 // We might get an arbitrary type spec type back. We should at
5007 // least always get a type spec type, though.
5008 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5009 NewTL.setNameLoc(TL.getNameLoc());
5010
5011 return Result;
5012}
5013
Douglas Gregord6ff3322009-08-04 16:50:30 +00005014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005015QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005016 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005017 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005018 TypedefNameDecl *Typedef
5019 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5020 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021 if (!Typedef)
5022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005023
John McCall550e0c22009-10-21 00:40:46 +00005024 QualType Result = TL.getType();
5025 if (getDerived().AlwaysRebuild() ||
5026 Typedef != T->getDecl()) {
5027 Result = getDerived().RebuildTypedefType(Typedef);
5028 if (Result.isNull())
5029 return QualType();
5030 }
Mike Stump11289f42009-09-09 15:08:12 +00005031
John McCall550e0c22009-10-21 00:40:46 +00005032 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5033 NewTL.setNameLoc(TL.getNameLoc());
5034
5035 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005036}
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregord6ff3322009-08-04 16:50:30 +00005038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005039QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005040 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005041 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005042 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5043 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005044
John McCalldadc5752010-08-24 06:29:42 +00005045 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005046 if (E.isInvalid())
5047 return QualType();
5048
Eli Friedmane4f22df2012-02-29 04:03:55 +00005049 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5050 if (E.isInvalid())
5051 return QualType();
5052
John McCall550e0c22009-10-21 00:40:46 +00005053 QualType Result = TL.getType();
5054 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005055 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005056 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005057 if (Result.isNull())
5058 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005059 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005060 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005061
John McCall550e0c22009-10-21 00:40:46 +00005062 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005063 NewTL.setTypeofLoc(TL.getTypeofLoc());
5064 NewTL.setLParenLoc(TL.getLParenLoc());
5065 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005066
5067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
5070template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005071QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005072 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005073 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5074 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5075 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005077
John McCall550e0c22009-10-21 00:40:46 +00005078 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005079 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5080 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005081 if (Result.isNull())
5082 return QualType();
5083 }
Mike Stump11289f42009-09-09 15:08:12 +00005084
John McCall550e0c22009-10-21 00:40:46 +00005085 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005086 NewTL.setTypeofLoc(TL.getTypeofLoc());
5087 NewTL.setLParenLoc(TL.getLParenLoc());
5088 NewTL.setRParenLoc(TL.getRParenLoc());
5089 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005090
5091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005092}
Mike Stump11289f42009-09-09 15:08:12 +00005093
5094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005095QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005096 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005097 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005098
Douglas Gregore922c772009-08-04 22:27:00 +00005099 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5101 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005102
John McCalldadc5752010-08-24 06:29:42 +00005103 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005104 if (E.isInvalid())
5105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005106
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005107 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005108 if (E.isInvalid())
5109 return QualType();
5110
John McCall550e0c22009-10-21 00:40:46 +00005111 QualType Result = TL.getType();
5112 if (getDerived().AlwaysRebuild() ||
5113 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005114 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005115 if (Result.isNull())
5116 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005117 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005118 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005119
John McCall550e0c22009-10-21 00:40:46 +00005120 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5121 NewTL.setNameLoc(TL.getNameLoc());
5122
5123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005124}
5125
5126template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005127QualType TreeTransform<Derived>::TransformUnaryTransformType(
5128 TypeLocBuilder &TLB,
5129 UnaryTransformTypeLoc TL) {
5130 QualType Result = TL.getType();
5131 if (Result->isDependentType()) {
5132 const UnaryTransformType *T = TL.getTypePtr();
5133 QualType NewBase =
5134 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5135 Result = getDerived().RebuildUnaryTransformType(NewBase,
5136 T->getUTTKind(),
5137 TL.getKWLoc());
5138 if (Result.isNull())
5139 return QualType();
5140 }
5141
5142 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5143 NewTL.setKWLoc(TL.getKWLoc());
5144 NewTL.setParensRange(TL.getParensRange());
5145 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5146 return Result;
5147}
5148
5149template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005150QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5151 AutoTypeLoc TL) {
5152 const AutoType *T = TL.getTypePtr();
5153 QualType OldDeduced = T->getDeducedType();
5154 QualType NewDeduced;
5155 if (!OldDeduced.isNull()) {
5156 NewDeduced = getDerived().TransformType(OldDeduced);
5157 if (NewDeduced.isNull())
5158 return QualType();
5159 }
5160
5161 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005162 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5163 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005164 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005165 if (Result.isNull())
5166 return QualType();
5167 }
5168
5169 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5170 NewTL.setNameLoc(TL.getNameLoc());
5171
5172 return Result;
5173}
5174
5175template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005176QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005177 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005178 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005179 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005180 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5181 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005182 if (!Record)
5183 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005184
John McCall550e0c22009-10-21 00:40:46 +00005185 QualType Result = TL.getType();
5186 if (getDerived().AlwaysRebuild() ||
5187 Record != T->getDecl()) {
5188 Result = getDerived().RebuildRecordType(Record);
5189 if (Result.isNull())
5190 return QualType();
5191 }
Mike Stump11289f42009-09-09 15:08:12 +00005192
John McCall550e0c22009-10-21 00:40:46 +00005193 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5194 NewTL.setNameLoc(TL.getNameLoc());
5195
5196 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005197}
Mike Stump11289f42009-09-09 15:08:12 +00005198
5199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005200QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005201 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005202 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005203 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005204 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5205 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005206 if (!Enum)
5207 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005208
John McCall550e0c22009-10-21 00:40:46 +00005209 QualType Result = TL.getType();
5210 if (getDerived().AlwaysRebuild() ||
5211 Enum != T->getDecl()) {
5212 Result = getDerived().RebuildEnumType(Enum);
5213 if (Result.isNull())
5214 return QualType();
5215 }
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCall550e0c22009-10-21 00:40:46 +00005217 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5218 NewTL.setNameLoc(TL.getNameLoc());
5219
5220 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221}
John McCallfcc33b02009-09-05 00:15:47 +00005222
John McCalle78aac42010-03-10 03:28:59 +00005223template<typename Derived>
5224QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5225 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005226 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005227 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5228 TL.getTypePtr()->getDecl());
5229 if (!D) return QualType();
5230
5231 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5232 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5233 return T;
5234}
5235
Douglas Gregord6ff3322009-08-04 16:50:30 +00005236template<typename Derived>
5237QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005238 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005239 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005240 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241}
5242
Mike Stump11289f42009-09-09 15:08:12 +00005243template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005244QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005245 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005246 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005247 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005248
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005249 // Substitute into the replacement type, which itself might involve something
5250 // that needs to be transformed. This only tends to occur with default
5251 // template arguments of template template parameters.
5252 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5253 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5254 if (Replacement.isNull())
5255 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005257 // Always canonicalize the replacement type.
5258 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5259 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005260 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005261 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005262
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005263 // Propagate type-source information.
5264 SubstTemplateTypeParmTypeLoc NewTL
5265 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5266 NewTL.setNameLoc(TL.getNameLoc());
5267 return Result;
5268
John McCallcebee162009-10-18 09:09:24 +00005269}
5270
5271template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005272QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5273 TypeLocBuilder &TLB,
5274 SubstTemplateTypeParmPackTypeLoc TL) {
5275 return TransformTypeSpecType(TLB, TL);
5276}
5277
5278template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005279QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005280 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005281 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005282 const TemplateSpecializationType *T = TL.getTypePtr();
5283
Douglas Gregordf846d12011-03-02 18:46:51 +00005284 // The nested-name-specifier never matters in a TemplateSpecializationType,
5285 // because we can't have a dependent nested-name-specifier anyway.
5286 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005287 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005288 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5289 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005290 if (Template.isNull())
5291 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005292
John McCall31f82722010-11-12 08:19:04 +00005293 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5294}
5295
Eli Friedman0dfb8892011-10-06 23:00:33 +00005296template<typename Derived>
5297QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5298 AtomicTypeLoc TL) {
5299 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5300 if (ValueType.isNull())
5301 return QualType();
5302
5303 QualType Result = TL.getType();
5304 if (getDerived().AlwaysRebuild() ||
5305 ValueType != TL.getValueLoc().getType()) {
5306 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5307 if (Result.isNull())
5308 return QualType();
5309 }
5310
5311 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5312 NewTL.setKWLoc(TL.getKWLoc());
5313 NewTL.setLParenLoc(TL.getLParenLoc());
5314 NewTL.setRParenLoc(TL.getRParenLoc());
5315
5316 return Result;
5317}
5318
Chad Rosier1dcde962012-08-08 18:46:20 +00005319 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005320 /// container that provides a \c getArgLoc() member function.
5321 ///
5322 /// This iterator is intended to be used with the iterator form of
5323 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5324 template<typename ArgLocContainer>
5325 class TemplateArgumentLocContainerIterator {
5326 ArgLocContainer *Container;
5327 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005328
Douglas Gregorfe921a72010-12-20 23:36:19 +00005329 public:
5330 typedef TemplateArgumentLoc value_type;
5331 typedef TemplateArgumentLoc reference;
5332 typedef int difference_type;
5333 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005334
Douglas Gregorfe921a72010-12-20 23:36:19 +00005335 class pointer {
5336 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005337
Douglas Gregorfe921a72010-12-20 23:36:19 +00005338 public:
5339 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005340
Douglas Gregorfe921a72010-12-20 23:36:19 +00005341 const TemplateArgumentLoc *operator->() const {
5342 return &Arg;
5343 }
5344 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005345
5346
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005347 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005348
Douglas Gregorfe921a72010-12-20 23:36:19 +00005349 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5350 unsigned Index)
5351 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005352
Douglas Gregorfe921a72010-12-20 23:36:19 +00005353 TemplateArgumentLocContainerIterator &operator++() {
5354 ++Index;
5355 return *this;
5356 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005357
Douglas Gregorfe921a72010-12-20 23:36:19 +00005358 TemplateArgumentLocContainerIterator operator++(int) {
5359 TemplateArgumentLocContainerIterator Old(*this);
5360 ++(*this);
5361 return Old;
5362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005363
Douglas Gregorfe921a72010-12-20 23:36:19 +00005364 TemplateArgumentLoc operator*() const {
5365 return Container->getArgLoc(Index);
5366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005367
Douglas Gregorfe921a72010-12-20 23:36:19 +00005368 pointer operator->() const {
5369 return pointer(Container->getArgLoc(Index));
5370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005371
Douglas Gregorfe921a72010-12-20 23:36:19 +00005372 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005373 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005374 return X.Container == Y.Container && X.Index == Y.Index;
5375 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005376
Douglas Gregorfe921a72010-12-20 23:36:19 +00005377 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005378 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005379 return !(X == Y);
5380 }
5381 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005382
5383
John McCall31f82722010-11-12 08:19:04 +00005384template <typename Derived>
5385QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5386 TypeLocBuilder &TLB,
5387 TemplateSpecializationTypeLoc TL,
5388 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005389 TemplateArgumentListInfo NewTemplateArgs;
5390 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5391 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005392 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5393 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005394 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005395 ArgIterator(TL, TL.getNumArgs()),
5396 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005397 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005398
John McCall0ad16662009-10-29 08:12:44 +00005399 // FIXME: maybe don't rebuild if all the template arguments are the same.
5400
5401 QualType Result =
5402 getDerived().RebuildTemplateSpecializationType(Template,
5403 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005404 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005405
5406 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005407 // Specializations of template template parameters are represented as
5408 // TemplateSpecializationTypes, and substitution of type alias templates
5409 // within a dependent context can transform them into
5410 // DependentTemplateSpecializationTypes.
5411 if (isa<DependentTemplateSpecializationType>(Result)) {
5412 DependentTemplateSpecializationTypeLoc NewTL
5413 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005414 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005415 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005416 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005417 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005418 NewTL.setLAngleLoc(TL.getLAngleLoc());
5419 NewTL.setRAngleLoc(TL.getRAngleLoc());
5420 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5421 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5422 return Result;
5423 }
5424
John McCall0ad16662009-10-29 08:12:44 +00005425 TemplateSpecializationTypeLoc NewTL
5426 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005427 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005428 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5429 NewTL.setLAngleLoc(TL.getLAngleLoc());
5430 NewTL.setRAngleLoc(TL.getRAngleLoc());
5431 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5432 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005433 }
Mike Stump11289f42009-09-09 15:08:12 +00005434
John McCall0ad16662009-10-29 08:12:44 +00005435 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436}
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregor5a064722011-02-28 17:23:35 +00005438template <typename Derived>
5439QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5440 TypeLocBuilder &TLB,
5441 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005442 TemplateName Template,
5443 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005444 TemplateArgumentListInfo NewTemplateArgs;
5445 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5446 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5447 typedef TemplateArgumentLocContainerIterator<
5448 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005449 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005450 ArgIterator(TL, TL.getNumArgs()),
5451 NewTemplateArgs))
5452 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005453
Douglas Gregor5a064722011-02-28 17:23:35 +00005454 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005455
Douglas Gregor5a064722011-02-28 17:23:35 +00005456 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5457 QualType Result
5458 = getSema().Context.getDependentTemplateSpecializationType(
5459 TL.getTypePtr()->getKeyword(),
5460 DTN->getQualifier(),
5461 DTN->getIdentifier(),
5462 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005463
Douglas Gregor5a064722011-02-28 17:23:35 +00005464 DependentTemplateSpecializationTypeLoc NewTL
5465 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005466 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005467 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005468 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005469 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005470 NewTL.setLAngleLoc(TL.getLAngleLoc());
5471 NewTL.setRAngleLoc(TL.getRAngleLoc());
5472 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5473 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5474 return Result;
5475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005476
5477 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005478 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005479 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005480 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005481
Douglas Gregor5a064722011-02-28 17:23:35 +00005482 if (!Result.isNull()) {
5483 /// FIXME: Wrap this in an elaborated-type-specifier?
5484 TemplateSpecializationTypeLoc NewTL
5485 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005486 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005487 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005488 NewTL.setLAngleLoc(TL.getLAngleLoc());
5489 NewTL.setRAngleLoc(TL.getRAngleLoc());
5490 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5491 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005493
Douglas Gregor5a064722011-02-28 17:23:35 +00005494 return Result;
5495}
5496
Mike Stump11289f42009-09-09 15:08:12 +00005497template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005498QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005499TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005500 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005501 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005502
Douglas Gregor844cb502011-03-01 18:12:44 +00005503 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005504 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005505 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005506 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005507 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5508 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005509 return QualType();
5510 }
Mike Stump11289f42009-09-09 15:08:12 +00005511
John McCall31f82722010-11-12 08:19:04 +00005512 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5513 if (NamedT.isNull())
5514 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005515
Richard Smith3f1b5d02011-05-05 21:57:07 +00005516 // C++0x [dcl.type.elab]p2:
5517 // If the identifier resolves to a typedef-name or the simple-template-id
5518 // resolves to an alias template specialization, the
5519 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005520 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5521 if (const TemplateSpecializationType *TST =
5522 NamedT->getAs<TemplateSpecializationType>()) {
5523 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005524 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5525 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005526 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5527 diag::err_tag_reference_non_tag) << 4;
5528 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5529 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005530 }
5531 }
5532
John McCall550e0c22009-10-21 00:40:46 +00005533 QualType Result = TL.getType();
5534 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005535 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005536 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005537 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005538 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005539 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005540 if (Result.isNull())
5541 return QualType();
5542 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005543
Abramo Bagnara6150c882010-05-11 21:36:43 +00005544 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005545 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005546 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005548}
Mike Stump11289f42009-09-09 15:08:12 +00005549
5550template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005551QualType TreeTransform<Derived>::TransformAttributedType(
5552 TypeLocBuilder &TLB,
5553 AttributedTypeLoc TL) {
5554 const AttributedType *oldType = TL.getTypePtr();
5555 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5556 if (modifiedType.isNull())
5557 return QualType();
5558
5559 QualType result = TL.getType();
5560
5561 // FIXME: dependent operand expressions?
5562 if (getDerived().AlwaysRebuild() ||
5563 modifiedType != oldType->getModifiedType()) {
5564 // TODO: this is really lame; we should really be rebuilding the
5565 // equivalent type from first principles.
5566 QualType equivalentType
5567 = getDerived().TransformType(oldType->getEquivalentType());
5568 if (equivalentType.isNull())
5569 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005570
5571 // Check whether we can add nullability; it is only represented as
5572 // type sugar, and therefore cannot be diagnosed in any other way.
5573 if (auto nullability = oldType->getImmediateNullability()) {
5574 if (!modifiedType->canHaveNullability()) {
5575 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005576 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005577 return QualType();
5578 }
5579 }
5580
John McCall81904512011-01-06 01:58:22 +00005581 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5582 modifiedType,
5583 equivalentType);
5584 }
5585
5586 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5587 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5588 if (TL.hasAttrOperand())
5589 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5590 if (TL.hasAttrExprOperand())
5591 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5592 else if (TL.hasAttrEnumOperand())
5593 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5594
5595 return result;
5596}
5597
5598template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005599QualType
5600TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5601 ParenTypeLoc TL) {
5602 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5603 if (Inner.isNull())
5604 return QualType();
5605
5606 QualType Result = TL.getType();
5607 if (getDerived().AlwaysRebuild() ||
5608 Inner != TL.getInnerLoc().getType()) {
5609 Result = getDerived().RebuildParenType(Inner);
5610 if (Result.isNull())
5611 return QualType();
5612 }
5613
5614 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5615 NewTL.setLParenLoc(TL.getLParenLoc());
5616 NewTL.setRParenLoc(TL.getRParenLoc());
5617 return Result;
5618}
5619
5620template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005621QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005622 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005623 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005624
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005625 NestedNameSpecifierLoc QualifierLoc
5626 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5627 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005628 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005629
John McCallc392f372010-06-11 00:33:02 +00005630 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005631 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005632 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005633 QualifierLoc,
5634 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005635 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005636 if (Result.isNull())
5637 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005638
Abramo Bagnarad7548482010-05-19 21:37:53 +00005639 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5640 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005641 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5642
Abramo Bagnarad7548482010-05-19 21:37:53 +00005643 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005644 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005645 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005646 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005647 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005648 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005649 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005650 NewTL.setNameLoc(TL.getNameLoc());
5651 }
John McCall550e0c22009-10-21 00:40:46 +00005652 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005653}
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregord6ff3322009-08-04 16:50:30 +00005655template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005656QualType TreeTransform<Derived>::
5657 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005658 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005659 NestedNameSpecifierLoc QualifierLoc;
5660 if (TL.getQualifierLoc()) {
5661 QualifierLoc
5662 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5663 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005664 return QualType();
5665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005666
John McCall31f82722010-11-12 08:19:04 +00005667 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005668 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005669}
5670
5671template<typename Derived>
5672QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005673TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5674 DependentTemplateSpecializationTypeLoc TL,
5675 NestedNameSpecifierLoc QualifierLoc) {
5676 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005677
Douglas Gregora7a795b2011-03-01 20:11:18 +00005678 TemplateArgumentListInfo NewTemplateArgs;
5679 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5680 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005681
Douglas Gregora7a795b2011-03-01 20:11:18 +00005682 typedef TemplateArgumentLocContainerIterator<
5683 DependentTemplateSpecializationTypeLoc> ArgIterator;
5684 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5685 ArgIterator(TL, TL.getNumArgs()),
5686 NewTemplateArgs))
5687 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005688
Douglas Gregora7a795b2011-03-01 20:11:18 +00005689 QualType Result
5690 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5691 QualifierLoc,
5692 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005693 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005694 NewTemplateArgs);
5695 if (Result.isNull())
5696 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005697
Douglas Gregora7a795b2011-03-01 20:11:18 +00005698 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5699 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005700
Douglas Gregora7a795b2011-03-01 20:11:18 +00005701 // Copy information relevant to the template specialization.
5702 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005703 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005704 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005705 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005706 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5707 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005708 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005709 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
Douglas Gregora7a795b2011-03-01 20:11:18 +00005711 // Copy information relevant to the elaborated type.
5712 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005713 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005714 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005715 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5716 DependentTemplateSpecializationTypeLoc SpecTL
5717 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005718 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005719 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005720 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005721 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005722 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5723 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005724 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005725 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005726 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005727 TemplateSpecializationTypeLoc SpecTL
5728 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005729 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005730 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005731 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5732 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005733 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005734 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005735 }
5736 return Result;
5737}
5738
5739template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005740QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5741 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005742 QualType Pattern
5743 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005744 if (Pattern.isNull())
5745 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005746
5747 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005748 if (getDerived().AlwaysRebuild() ||
5749 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005750 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005751 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005752 TL.getEllipsisLoc(),
5753 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005754 if (Result.isNull())
5755 return QualType();
5756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005757
Douglas Gregor822d0302011-01-12 17:07:58 +00005758 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5759 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5760 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005761}
5762
5763template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005764QualType
5765TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005766 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005767 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005768 TLB.pushFullCopy(TL);
5769 return TL.getType();
5770}
5771
5772template<typename Derived>
5773QualType
5774TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005775 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005776 // Transform base type.
5777 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5778 if (BaseType.isNull())
5779 return QualType();
5780
5781 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5782
5783 // Transform type arguments.
5784 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5785 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5786 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5787 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5788 QualType TypeArg = TypeArgInfo->getType();
5789 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5790 AnyChanged = true;
5791
5792 // We have a pack expansion. Instantiate it.
5793 const auto *PackExpansion = PackExpansionLoc.getType()
5794 ->castAs<PackExpansionType>();
5795 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5796 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5797 Unexpanded);
5798 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5799
5800 // Determine whether the set of unexpanded parameter packs can
5801 // and should be expanded.
5802 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5803 bool Expand = false;
5804 bool RetainExpansion = false;
5805 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5806 if (getDerived().TryExpandParameterPacks(
5807 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5808 Unexpanded, Expand, RetainExpansion, NumExpansions))
5809 return QualType();
5810
5811 if (!Expand) {
5812 // We can't expand this pack expansion into separate arguments yet;
5813 // just substitute into the pattern and create a new pack expansion
5814 // type.
5815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5816
5817 TypeLocBuilder TypeArgBuilder;
5818 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5819 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5820 PatternLoc);
5821 if (NewPatternType.isNull())
5822 return QualType();
5823
5824 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5825 NewPatternType, NumExpansions);
5826 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5827 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5828 NewTypeArgInfos.push_back(
5829 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5830 continue;
5831 }
5832
5833 // Substitute into the pack expansion pattern for each slice of the
5834 // pack.
5835 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5836 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5837
5838 TypeLocBuilder TypeArgBuilder;
5839 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5840
5841 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5842 PatternLoc);
5843 if (NewTypeArg.isNull())
5844 return QualType();
5845
5846 NewTypeArgInfos.push_back(
5847 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5848 }
5849
5850 continue;
5851 }
5852
5853 TypeLocBuilder TypeArgBuilder;
5854 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5855 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5856 if (NewTypeArg.isNull())
5857 return QualType();
5858
5859 // If nothing changed, just keep the old TypeSourceInfo.
5860 if (NewTypeArg == TypeArg) {
5861 NewTypeArgInfos.push_back(TypeArgInfo);
5862 continue;
5863 }
5864
5865 NewTypeArgInfos.push_back(
5866 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5867 AnyChanged = true;
5868 }
5869
5870 QualType Result = TL.getType();
5871 if (getDerived().AlwaysRebuild() || AnyChanged) {
5872 // Rebuild the type.
5873 Result = getDerived().RebuildObjCObjectType(
5874 BaseType,
5875 TL.getLocStart(),
5876 TL.getTypeArgsLAngleLoc(),
5877 NewTypeArgInfos,
5878 TL.getTypeArgsRAngleLoc(),
5879 TL.getProtocolLAngleLoc(),
5880 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5881 TL.getNumProtocols()),
5882 TL.getProtocolLocs(),
5883 TL.getProtocolRAngleLoc());
5884
5885 if (Result.isNull())
5886 return QualType();
5887 }
5888
5889 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5890 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5891 NewT.setHasBaseTypeAsWritten(true);
5892 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5893 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5894 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5895 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5896 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5897 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5898 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5899 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5900 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005901}
Mike Stump11289f42009-09-09 15:08:12 +00005902
5903template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005904QualType
5905TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005906 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005907 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5908 if (PointeeType.isNull())
5909 return QualType();
5910
5911 QualType Result = TL.getType();
5912 if (getDerived().AlwaysRebuild() ||
5913 PointeeType != TL.getPointeeLoc().getType()) {
5914 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5915 TL.getStarLoc());
5916 if (Result.isNull())
5917 return QualType();
5918 }
5919
5920 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5921 NewT.setStarLoc(TL.getStarLoc());
5922 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005923}
5924
Douglas Gregord6ff3322009-08-04 16:50:30 +00005925//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005926// Statement transformation
5927//===----------------------------------------------------------------------===//
5928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005929StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005930TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005931 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005932}
5933
5934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005935StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005936TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5937 return getDerived().TransformCompoundStmt(S, false);
5938}
5939
5940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005942TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005943 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005944 Sema::CompoundScopeRAII CompoundScope(getSema());
5945
John McCall1ababa62010-08-27 19:56:05 +00005946 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005947 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005948 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005949 for (auto *B : S->body()) {
5950 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005951 if (Result.isInvalid()) {
5952 // Immediately fail if this was a DeclStmt, since it's very
5953 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005954 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005955 return StmtError();
5956
5957 // Otherwise, just keep processing substatements and fail later.
5958 SubStmtInvalid = true;
5959 continue;
5960 }
Mike Stump11289f42009-09-09 15:08:12 +00005961
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005962 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005963 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005964 }
Mike Stump11289f42009-09-09 15:08:12 +00005965
John McCall1ababa62010-08-27 19:56:05 +00005966 if (SubStmtInvalid)
5967 return StmtError();
5968
Douglas Gregorebe10102009-08-20 07:17:43 +00005969 if (!getDerived().AlwaysRebuild() &&
5970 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005971 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005972
5973 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005974 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005975 S->getRBracLoc(),
5976 IsStmtExpr);
5977}
Mike Stump11289f42009-09-09 15:08:12 +00005978
Douglas Gregorebe10102009-08-20 07:17:43 +00005979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005981TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005982 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005983 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005984 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5985 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005986
Eli Friedman06577382009-11-19 03:14:00 +00005987 // Transform the left-hand case value.
5988 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005989 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005990 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005992
Eli Friedman06577382009-11-19 03:14:00 +00005993 // Transform the right-hand case value (for the GNU case-range extension).
5994 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005995 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005996 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005997 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005998 }
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 // Build the case statement.
6001 // Case statements are always rebuilt so that they will attached to their
6002 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006003 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006004 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006005 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006006 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006007 S->getColonLoc());
6008 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregorebe10102009-08-20 07:17:43 +00006011 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006012 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
Douglas Gregorebe10102009-08-20 07:17:43 +00006016 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006017 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006018}
6019
6020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006021StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006022TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006023 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006024 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006025 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006026 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 // Default statements are always rebuilt
6029 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006030 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006031}
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006034StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006035TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006036 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006037 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006038 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006039
Chris Lattnercab02a62011-02-17 20:34:02 +00006040 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6041 S->getDecl());
6042 if (!LD)
6043 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006044
6045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006047 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006048 cast<LabelDecl>(LD), SourceLocation(),
6049 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006050}
Mike Stump11289f42009-09-09 15:08:12 +00006051
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006052template <typename Derived>
6053const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6054 if (!R)
6055 return R;
6056
6057 switch (R->getKind()) {
6058// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6059#define ATTR(X)
6060#define PRAGMA_SPELLING_ATTR(X) \
6061 case attr::X: \
6062 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6063#include "clang/Basic/AttrList.inc"
6064 default:
6065 return R;
6066 }
6067}
6068
6069template <typename Derived>
6070StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6071 bool AttrsChanged = false;
6072 SmallVector<const Attr *, 1> Attrs;
6073
6074 // Visit attributes and keep track if any are transformed.
6075 for (const auto *I : S->getAttrs()) {
6076 const Attr *R = getDerived().TransformAttr(I);
6077 AttrsChanged |= (I != R);
6078 Attrs.push_back(R);
6079 }
6080
Richard Smithc202b282012-04-14 00:33:13 +00006081 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6082 if (SubStmt.isInvalid())
6083 return StmtError();
6084
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006085 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006086 return S;
6087
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006088 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006089 SubStmt.get());
6090}
6091
6092template<typename Derived>
6093StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006094TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006096 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006097 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006098 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006099 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006100 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006101 getDerived().TransformDefinition(
6102 S->getConditionVariable()->getLocation(),
6103 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006104 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006106 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006107 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006108
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006109 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006111
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006112 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006113 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006114 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006115 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006116 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006118
John McCallb268a282010-08-23 23:25:46 +00006119 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006120 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006121 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006122
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006123 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006124 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Douglas Gregorebe10102009-08-20 07:17:43 +00006127 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006128 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006129 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregorebe10102009-08-20 07:17:43 +00006132 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006133 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006138 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006139 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006140 Then.get() == S->getThen() &&
6141 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006142 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006144 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006145 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006146 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006147}
6148
6149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006150StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006151TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006153 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006154 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006155 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006156 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006157 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006158 getDerived().TransformDefinition(
6159 S->getConditionVariable()->getLocation(),
6160 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006161 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006163 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006164 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006165
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006166 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006168 }
Mike Stump11289f42009-09-09 15:08:12 +00006169
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006171 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006172 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006173 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
Douglas Gregorebe10102009-08-20 07:17:43 +00006177 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006178 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregorebe10102009-08-20 07:17:43 +00006182 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006183 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6184 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006185}
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregorebe10102009-08-20 07:17:43 +00006187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006188StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006189TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006191 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006192 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006193 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006194 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006195 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006196 getDerived().TransformDefinition(
6197 S->getConditionVariable()->getLocation(),
6198 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006199 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006200 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006201 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006202 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006203
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006204 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006206
6207 if (S->getCond()) {
6208 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006209 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6210 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006211 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006212 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006214 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006215 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006216 }
Mike Stump11289f42009-09-09 15:08:12 +00006217
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006218 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006219 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006220 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006221
Douglas Gregorebe10102009-08-20 07:17:43 +00006222 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006223 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006224 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006225 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregorebe10102009-08-20 07:17:43 +00006227 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006228 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006229 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006231 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006233 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006234 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006235}
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregorebe10102009-08-20 07:17:43 +00006237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006238StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006239TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006240 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006241 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006245 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006246 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006247 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006249
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 if (!getDerived().AlwaysRebuild() &&
6251 Cond.get() == S->getCond() &&
6252 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006253 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006254
John McCallb268a282010-08-23 23:25:46 +00006255 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6256 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006257 S->getRParenLoc());
6258}
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregorebe10102009-08-20 07:17:43 +00006260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006261StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006262TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006263 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006264 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006266 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006269 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006270 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006271 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006272 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006273 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006274 getDerived().TransformDefinition(
6275 S->getConditionVariable()->getLocation(),
6276 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006277 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006278 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006279 } else {
6280 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006282 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006284
6285 if (S->getCond()) {
6286 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006287 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6288 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006289 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006290 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006292
John McCallb268a282010-08-23 23:25:46 +00006293 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006294 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006295 }
Mike Stump11289f42009-09-09 15:08:12 +00006296
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006297 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006298 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006300
Douglas Gregorebe10102009-08-20 07:17:43 +00006301 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006302 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006303 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006305
Richard Smith945f8d32013-01-14 22:39:08 +00006306 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006307 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006308 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006309
Douglas Gregorebe10102009-08-20 07:17:43 +00006310 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006311 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006312 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006313 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregorebe10102009-08-20 07:17:43 +00006315 if (!getDerived().AlwaysRebuild() &&
6316 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006317 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006318 Inc.get() == S->getInc() &&
6319 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006320 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006323 Init.get(), FullCond, ConditionVar,
6324 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006325}
6326
6327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006328StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006329TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006330 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6331 S->getLabel());
6332 if (!LD)
6333 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006334
Douglas Gregorebe10102009-08-20 07:17:43 +00006335 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006336 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006337 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006338}
6339
6340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006341StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006342TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006343 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006344 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006346 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 if (!getDerived().AlwaysRebuild() &&
6349 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006350 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006351
6352 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006353 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006354}
6355
6356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006358TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006359 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006360}
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregorebe10102009-08-20 07:17:43 +00006362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006364TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006365 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006366}
Mike Stump11289f42009-09-09 15:08:12 +00006367
Douglas Gregorebe10102009-08-20 07:17:43 +00006368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006370TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006371 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6372 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006373 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006374 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006375
Mike Stump11289f42009-09-09 15:08:12 +00006376 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006377 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006378 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006379}
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006383TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006384 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006385 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006386 for (auto *D : S->decls()) {
6387 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006388 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006390
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006391 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006392 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 Decls.push_back(Transformed);
6395 }
Mike Stump11289f42009-09-09 15:08:12 +00006396
Douglas Gregorebe10102009-08-20 07:17:43 +00006397 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006398 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006399
Rafael Espindolaab417692013-07-09 12:05:01 +00006400 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006401}
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregorebe10102009-08-20 07:17:43 +00006403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006404StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006405TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006406
Benjamin Kramerf0623432012-08-23 22:51:59 +00006407 SmallVector<Expr*, 8> Constraints;
6408 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006409 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006410
John McCalldadc5752010-08-24 06:29:42 +00006411 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006412 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006413
6414 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006415
Anders Carlssonaaeef072010-01-24 05:50:09 +00006416 // Go through the outputs.
6417 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006418 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006419
Anders Carlssonaaeef072010-01-24 05:50:09 +00006420 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006421 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006422
Anders Carlssonaaeef072010-01-24 05:50:09 +00006423 // Transform the output expr.
6424 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006425 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006426 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006428
Anders Carlssonaaeef072010-01-24 05:50:09 +00006429 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006430
John McCallb268a282010-08-23 23:25:46 +00006431 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006432 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006433
Anders Carlssonaaeef072010-01-24 05:50:09 +00006434 // Go through the inputs.
6435 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006436 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006437
Anders Carlssonaaeef072010-01-24 05:50:09 +00006438 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006439 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006440
Anders Carlssonaaeef072010-01-24 05:50:09 +00006441 // Transform the input expr.
6442 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006443 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006444 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006446
Anders Carlssonaaeef072010-01-24 05:50:09 +00006447 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006448
John McCallb268a282010-08-23 23:25:46 +00006449 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006451
Anders Carlssonaaeef072010-01-24 05:50:09 +00006452 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006453 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006454
6455 // Go through the clobbers.
6456 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006457 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006458
6459 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006460 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006461 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6462 S->isVolatile(), S->getNumOutputs(),
6463 S->getNumInputs(), Names.data(),
6464 Constraints, Exprs, AsmString.get(),
6465 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006466}
6467
Chad Rosier32503022012-06-11 20:47:18 +00006468template<typename Derived>
6469StmtResult
6470TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006471 ArrayRef<Token> AsmToks =
6472 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006473
John McCallf413f5e2013-05-03 00:10:13 +00006474 bool HadError = false, HadChange = false;
6475
6476 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6477 SmallVector<Expr*, 8> TransformedExprs;
6478 TransformedExprs.reserve(SrcExprs.size());
6479 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6480 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6481 if (!Result.isUsable()) {
6482 HadError = true;
6483 } else {
6484 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006485 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006486 }
6487 }
6488
6489 if (HadError) return StmtError();
6490 if (!HadChange && !getDerived().AlwaysRebuild())
6491 return Owned(S);
6492
Chad Rosierb6f46c12012-08-15 16:53:30 +00006493 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006494 AsmToks, S->getAsmString(),
6495 S->getNumOutputs(), S->getNumInputs(),
6496 S->getAllConstraints(), S->getClobbers(),
6497 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006498}
Douglas Gregorebe10102009-08-20 07:17:43 +00006499
Richard Smith9f690bd2015-10-27 06:02:45 +00006500// C++ Coroutines TS
6501
6502template<typename Derived>
6503StmtResult
6504TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6505 // The coroutine body should be re-formed by the caller if necessary.
6506 return getDerived().TransformStmt(S->getBody());
6507}
6508
6509template<typename Derived>
6510StmtResult
6511TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6512 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6513 /*NotCopyInit*/false);
6514 if (Result.isInvalid())
6515 return StmtError();
6516
6517 // Always rebuild; we don't know if this needs to be injected into a new
6518 // context or if the promise type has changed.
6519 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6520}
6521
6522template<typename Derived>
6523ExprResult
6524TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6525 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6526 /*NotCopyInit*/false);
6527 if (Result.isInvalid())
6528 return ExprError();
6529
6530 // Always rebuild; we don't know if this needs to be injected into a new
6531 // context or if the promise type has changed.
6532 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6533}
6534
6535template<typename Derived>
6536ExprResult
6537TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6538 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6539 /*NotCopyInit*/false);
6540 if (Result.isInvalid())
6541 return ExprError();
6542
6543 // Always rebuild; we don't know if this needs to be injected into a new
6544 // context or if the promise type has changed.
6545 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6546}
6547
6548// Objective-C Statements.
6549
Douglas Gregorebe10102009-08-20 07:17:43 +00006550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006551StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006552TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006553 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006554 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006555 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006557
Douglas Gregor96c79492010-04-23 22:50:49 +00006558 // Transform the @catch statements (if present).
6559 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006560 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006561 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006562 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006563 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006564 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006565 if (Catch.get() != S->getCatchStmt(I))
6566 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006567 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006568 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006569
Douglas Gregor306de2f2010-04-22 23:59:56 +00006570 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006571 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006572 if (S->getFinallyStmt()) {
6573 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6574 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006575 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006576 }
6577
6578 // If nothing changed, just retain this statement.
6579 if (!getDerived().AlwaysRebuild() &&
6580 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006581 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006582 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006583 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006584
Douglas Gregor306de2f2010-04-22 23:59:56 +00006585 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006586 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006587 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006588}
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregorebe10102009-08-20 07:17:43 +00006590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006591StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006592TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006593 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006594 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006595 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006596 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006597 if (FromVar->getTypeSourceInfo()) {
6598 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6599 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006602
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006603 QualType T;
6604 if (TSInfo)
6605 T = TSInfo->getType();
6606 else {
6607 T = getDerived().TransformType(FromVar->getType());
6608 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006609 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006611
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006612 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6613 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006614 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006615 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006616
John McCalldadc5752010-08-24 06:29:42 +00006617 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006618 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006620
6621 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006622 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006623 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006624}
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregorebe10102009-08-20 07:17:43 +00006626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006628TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006629 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006630 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006631 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006633
Douglas Gregor306de2f2010-04-22 23:59:56 +00006634 // If nothing changed, just retain this statement.
6635 if (!getDerived().AlwaysRebuild() &&
6636 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006637 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006638
6639 // Build a new statement.
6640 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006641 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006642}
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregorebe10102009-08-20 07:17:43 +00006644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006645StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006646TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006647 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006648 if (S->getThrowExpr()) {
6649 Operand = getDerived().TransformExpr(S->getThrowExpr());
6650 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006652 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006653
Douglas Gregor2900c162010-04-22 21:44:01 +00006654 if (!getDerived().AlwaysRebuild() &&
6655 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006656 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006657
John McCallb268a282010-08-23 23:25:46 +00006658 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006659}
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregorebe10102009-08-20 07:17:43 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006663TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006664 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006665 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006666 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006667 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006668 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006669 Object =
6670 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6671 Object.get());
6672 if (Object.isInvalid())
6673 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006674
Douglas Gregor6148de72010-04-22 22:01:21 +00006675 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006676 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006677 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006679
Douglas Gregor6148de72010-04-22 22:01:21 +00006680 // If nothing change, just retain the current statement.
6681 if (!getDerived().AlwaysRebuild() &&
6682 Object.get() == S->getSynchExpr() &&
6683 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006684 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006685
6686 // Build a new statement.
6687 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006688 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006689}
6690
6691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006692StmtResult
John McCall31168b02011-06-15 23:02:42 +00006693TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6694 ObjCAutoreleasePoolStmt *S) {
6695 // Transform the body.
6696 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6697 if (Body.isInvalid())
6698 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006699
John McCall31168b02011-06-15 23:02:42 +00006700 // If nothing changed, just retain this statement.
6701 if (!getDerived().AlwaysRebuild() &&
6702 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006703 return S;
John McCall31168b02011-06-15 23:02:42 +00006704
6705 // Build a new statement.
6706 return getDerived().RebuildObjCAutoreleasePoolStmt(
6707 S->getAtLoc(), Body.get());
6708}
6709
6710template<typename Derived>
6711StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006712TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006713 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006714 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006715 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006716 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006717 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006718
Douglas Gregorf68a5082010-04-22 23:10:45 +00006719 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006720 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006721 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006722 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006723
Douglas Gregorf68a5082010-04-22 23:10:45 +00006724 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006725 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006726 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006728
Douglas Gregorf68a5082010-04-22 23:10:45 +00006729 // If nothing changed, just retain this statement.
6730 if (!getDerived().AlwaysRebuild() &&
6731 Element.get() == S->getElement() &&
6732 Collection.get() == S->getCollection() &&
6733 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006734 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006735
Douglas Gregorf68a5082010-04-22 23:10:45 +00006736 // Build a new statement.
6737 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006738 Element.get(),
6739 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006740 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006741 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006742}
6743
David Majnemer5f7efef2013-10-15 09:50:08 +00006744template <typename Derived>
6745StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006746 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006747 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006748 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6749 TypeSourceInfo *T =
6750 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006751 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006752 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006753
David Majnemer5f7efef2013-10-15 09:50:08 +00006754 Var = getDerived().RebuildExceptionDecl(
6755 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6756 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006757 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006759 }
Mike Stump11289f42009-09-09 15:08:12 +00006760
Douglas Gregorebe10102009-08-20 07:17:43 +00006761 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006762 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006763 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006764 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006765
David Majnemer5f7efef2013-10-15 09:50:08 +00006766 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006767 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006768 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006769
David Majnemer5f7efef2013-10-15 09:50:08 +00006770 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006771}
Mike Stump11289f42009-09-09 15:08:12 +00006772
David Majnemer5f7efef2013-10-15 09:50:08 +00006773template <typename Derived>
6774StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006775 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006776 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006777 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006779
Douglas Gregorebe10102009-08-20 07:17:43 +00006780 // Transform the handlers.
6781 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006782 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006783 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006784 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006785 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006787
Douglas Gregorebe10102009-08-20 07:17:43 +00006788 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006789 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006790 }
Mike Stump11289f42009-09-09 15:08:12 +00006791
David Majnemer5f7efef2013-10-15 09:50:08 +00006792 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006793 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006794 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006795
John McCallb268a282010-08-23 23:25:46 +00006796 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006797 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006798}
Mike Stump11289f42009-09-09 15:08:12 +00006799
Richard Smith02e85f32011-04-14 22:09:26 +00006800template<typename Derived>
6801StmtResult
6802TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6803 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6804 if (Range.isInvalid())
6805 return StmtError();
6806
6807 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6808 if (BeginEnd.isInvalid())
6809 return StmtError();
6810
6811 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6812 if (Cond.isInvalid())
6813 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006814 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006815 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006816 if (Cond.isInvalid())
6817 return StmtError();
6818 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006819 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006820
6821 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6822 if (Inc.isInvalid())
6823 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006824 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006825 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006826
6827 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6828 if (LoopVar.isInvalid())
6829 return StmtError();
6830
6831 StmtResult NewStmt = S;
6832 if (getDerived().AlwaysRebuild() ||
6833 Range.get() != S->getRangeStmt() ||
6834 BeginEnd.get() != S->getBeginEndStmt() ||
6835 Cond.get() != S->getCond() ||
6836 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006837 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006838 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006839 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006840 S->getColonLoc(), Range.get(),
6841 BeginEnd.get(), Cond.get(),
6842 Inc.get(), LoopVar.get(),
6843 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006844 if (NewStmt.isInvalid())
6845 return StmtError();
6846 }
Richard Smith02e85f32011-04-14 22:09:26 +00006847
6848 StmtResult Body = getDerived().TransformStmt(S->getBody());
6849 if (Body.isInvalid())
6850 return StmtError();
6851
6852 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6853 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006854 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006855 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006856 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006857 S->getColonLoc(), Range.get(),
6858 BeginEnd.get(), Cond.get(),
6859 Inc.get(), LoopVar.get(),
6860 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006861 if (NewStmt.isInvalid())
6862 return StmtError();
6863 }
Richard Smith02e85f32011-04-14 22:09:26 +00006864
6865 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006866 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006867
6868 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6869}
6870
John Wiegley1c0675e2011-04-28 01:08:34 +00006871template<typename Derived>
6872StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006873TreeTransform<Derived>::TransformMSDependentExistsStmt(
6874 MSDependentExistsStmt *S) {
6875 // Transform the nested-name-specifier, if any.
6876 NestedNameSpecifierLoc QualifierLoc;
6877 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006878 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006879 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6880 if (!QualifierLoc)
6881 return StmtError();
6882 }
6883
6884 // Transform the declaration name.
6885 DeclarationNameInfo NameInfo = S->getNameInfo();
6886 if (NameInfo.getName()) {
6887 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6888 if (!NameInfo.getName())
6889 return StmtError();
6890 }
6891
6892 // Check whether anything changed.
6893 if (!getDerived().AlwaysRebuild() &&
6894 QualifierLoc == S->getQualifierLoc() &&
6895 NameInfo.getName() == S->getNameInfo().getName())
6896 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006897
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006898 // Determine whether this name exists, if we can.
6899 CXXScopeSpec SS;
6900 SS.Adopt(QualifierLoc);
6901 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006902 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006903 case Sema::IER_Exists:
6904 if (S->isIfExists())
6905 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006906
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006907 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6908
6909 case Sema::IER_DoesNotExist:
6910 if (S->isIfNotExists())
6911 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006912
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006913 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006914
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006915 case Sema::IER_Dependent:
6916 Dependent = true;
6917 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006918
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006919 case Sema::IER_Error:
6920 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006922
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006923 // We need to continue with the instantiation, so do so now.
6924 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6925 if (SubStmt.isInvalid())
6926 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006927
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006928 // If we have resolved the name, just transform to the substatement.
6929 if (!Dependent)
6930 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006931
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006932 // The name is still dependent, so build a dependent expression again.
6933 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6934 S->isIfExists(),
6935 QualifierLoc,
6936 NameInfo,
6937 SubStmt.get());
6938}
6939
6940template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006941ExprResult
6942TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6943 NestedNameSpecifierLoc QualifierLoc;
6944 if (E->getQualifierLoc()) {
6945 QualifierLoc
6946 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6947 if (!QualifierLoc)
6948 return ExprError();
6949 }
6950
6951 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6952 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6953 if (!PD)
6954 return ExprError();
6955
6956 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6957 if (Base.isInvalid())
6958 return ExprError();
6959
6960 return new (SemaRef.getASTContext())
6961 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6962 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6963 QualifierLoc, E->getMemberLoc());
6964}
6965
David Majnemerfad8f482013-10-15 09:33:02 +00006966template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00006967ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
6968 MSPropertySubscriptExpr *E) {
6969 auto BaseRes = getDerived().TransformExpr(E->getBase());
6970 if (BaseRes.isInvalid())
6971 return ExprError();
6972 auto IdxRes = getDerived().TransformExpr(E->getIdx());
6973 if (IdxRes.isInvalid())
6974 return ExprError();
6975
6976 if (!getDerived().AlwaysRebuild() &&
6977 BaseRes.get() == E->getBase() &&
6978 IdxRes.get() == E->getIdx())
6979 return E;
6980
6981 return getDerived().RebuildArraySubscriptExpr(
6982 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
6983}
6984
6985template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00006986StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006987 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006988 if (TryBlock.isInvalid())
6989 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006990
6991 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006992 if (Handler.isInvalid())
6993 return StmtError();
6994
David Majnemerfad8f482013-10-15 09:33:02 +00006995 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6996 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006997 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006998
Warren Huntf6be4cb2014-07-25 20:52:51 +00006999 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7000 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007001}
7002
David Majnemerfad8f482013-10-15 09:33:02 +00007003template <typename Derived>
7004StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007005 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007006 if (Block.isInvalid())
7007 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007008
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007009 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007010}
7011
David Majnemerfad8f482013-10-15 09:33:02 +00007012template <typename Derived>
7013StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007014 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007015 if (FilterExpr.isInvalid())
7016 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007017
David Majnemer7e755502013-10-15 09:30:14 +00007018 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007019 if (Block.isInvalid())
7020 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007021
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007022 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7023 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007024}
7025
David Majnemerfad8f482013-10-15 09:33:02 +00007026template <typename Derived>
7027StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7028 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007029 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7030 else
7031 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7032}
7033
Nico Weber9b982072014-07-07 00:12:30 +00007034template<typename Derived>
7035StmtResult
7036TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7037 return S;
7038}
7039
Alexander Musman64d33f12014-06-04 07:53:32 +00007040//===----------------------------------------------------------------------===//
7041// OpenMP directive transformation
7042//===----------------------------------------------------------------------===//
7043template <typename Derived>
7044StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7045 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007046
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007047 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007048 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007049 ArrayRef<OMPClause *> Clauses = D->clauses();
7050 TClauses.reserve(Clauses.size());
7051 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7052 I != E; ++I) {
7053 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007054 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007055 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007056 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007057 if (Clause)
7058 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007059 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007060 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007061 }
7062 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007063 StmtResult AssociatedStmt;
7064 if (D->hasAssociatedStmt()) {
7065 if (!D->getAssociatedStmt()) {
7066 return StmtError();
7067 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007068 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7069 /*CurScope=*/nullptr);
7070 StmtResult Body;
7071 {
7072 Sema::CompoundScopeRAII CompoundScope(getSema());
7073 Body = getDerived().TransformStmt(
7074 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7075 }
7076 AssociatedStmt =
7077 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007078 if (AssociatedStmt.isInvalid()) {
7079 return StmtError();
7080 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007081 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007082 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007083 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007084 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007085
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007086 // Transform directive name for 'omp critical' directive.
7087 DeclarationNameInfo DirName;
7088 if (D->getDirectiveKind() == OMPD_critical) {
7089 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7090 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7091 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007092 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7093 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7094 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007095 } else if (D->getDirectiveKind() == OMPD_cancel) {
7096 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007097 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007098
Alexander Musman64d33f12014-06-04 07:53:32 +00007099 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007100 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7101 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007102}
7103
Alexander Musman64d33f12014-06-04 07:53:32 +00007104template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007105StmtResult
7106TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7107 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007108 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7109 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7111 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7112 return Res;
7113}
7114
Alexander Musman64d33f12014-06-04 07:53:32 +00007115template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007116StmtResult
7117TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7118 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007119 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7120 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7122 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007123 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007124}
7125
Alexey Bataevf29276e2014-06-18 04:14:57 +00007126template <typename Derived>
7127StmtResult
7128TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7129 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007130 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7131 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7133 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7134 return Res;
7135}
7136
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007137template <typename Derived>
7138StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007139TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7140 DeclarationNameInfo DirName;
7141 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7142 D->getLocStart());
7143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7144 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7145 return Res;
7146}
7147
7148template <typename Derived>
7149StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007150TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7151 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007152 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7153 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7155 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7156 return Res;
7157}
7158
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007159template <typename Derived>
7160StmtResult
7161TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7162 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007163 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7164 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7167 return Res;
7168}
7169
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007170template <typename Derived>
7171StmtResult
7172TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7173 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007174 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7175 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7177 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7178 return Res;
7179}
7180
Alexey Bataev4acb8592014-07-07 13:01:15 +00007181template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007182StmtResult
7183TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7184 DeclarationNameInfo DirName;
7185 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7186 D->getLocStart());
7187 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7188 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7189 return Res;
7190}
7191
7192template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007193StmtResult
7194TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7195 getDerived().getSema().StartOpenMPDSABlock(
7196 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7199 return Res;
7200}
7201
7202template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007203StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7204 OMPParallelForDirective *D) {
7205 DeclarationNameInfo DirName;
7206 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7207 nullptr, D->getLocStart());
7208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7210 return Res;
7211}
7212
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007213template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007214StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7215 OMPParallelForSimdDirective *D) {
7216 DeclarationNameInfo DirName;
7217 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7218 nullptr, D->getLocStart());
7219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7221 return Res;
7222}
7223
7224template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007225StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7226 OMPParallelSectionsDirective *D) {
7227 DeclarationNameInfo DirName;
7228 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7229 nullptr, D->getLocStart());
7230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7232 return Res;
7233}
7234
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007235template <typename Derived>
7236StmtResult
7237TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7238 DeclarationNameInfo DirName;
7239 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7240 D->getLocStart());
7241 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7243 return Res;
7244}
7245
Alexey Bataev68446b72014-07-18 07:47:19 +00007246template <typename Derived>
7247StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7248 OMPTaskyieldDirective *D) {
7249 DeclarationNameInfo DirName;
7250 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7251 D->getLocStart());
7252 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7253 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7254 return Res;
7255}
7256
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007257template <typename Derived>
7258StmtResult
7259TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7260 DeclarationNameInfo DirName;
7261 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7262 D->getLocStart());
7263 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7264 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7265 return Res;
7266}
7267
Alexey Bataev2df347a2014-07-18 10:17:07 +00007268template <typename Derived>
7269StmtResult
7270TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7271 DeclarationNameInfo DirName;
7272 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7273 D->getLocStart());
7274 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7275 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7276 return Res;
7277}
7278
Alexey Bataev6125da92014-07-21 11:26:11 +00007279template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007280StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7281 OMPTaskgroupDirective *D) {
7282 DeclarationNameInfo DirName;
7283 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7284 D->getLocStart());
7285 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7286 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7287 return Res;
7288}
7289
7290template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007291StmtResult
7292TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7293 DeclarationNameInfo DirName;
7294 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7295 D->getLocStart());
7296 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7297 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7298 return Res;
7299}
7300
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007301template <typename Derived>
7302StmtResult
7303TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7304 DeclarationNameInfo DirName;
7305 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7306 D->getLocStart());
7307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7309 return Res;
7310}
7311
Alexey Bataev0162e452014-07-22 10:10:35 +00007312template <typename Derived>
7313StmtResult
7314TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7315 DeclarationNameInfo DirName;
7316 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7317 D->getLocStart());
7318 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7319 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7320 return Res;
7321}
7322
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007323template <typename Derived>
7324StmtResult
7325TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7326 DeclarationNameInfo DirName;
7327 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7328 D->getLocStart());
7329 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7330 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7331 return Res;
7332}
7333
Alexey Bataev13314bf2014-10-09 04:18:56 +00007334template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007335StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7336 OMPTargetDataDirective *D) {
7337 DeclarationNameInfo DirName;
7338 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7339 D->getLocStart());
7340 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7341 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7342 return Res;
7343}
7344
7345template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007346StmtResult
7347TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7348 DeclarationNameInfo DirName;
7349 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7350 D->getLocStart());
7351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7353 return Res;
7354}
7355
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007356template <typename Derived>
7357StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7358 OMPCancellationPointDirective *D) {
7359 DeclarationNameInfo DirName;
7360 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7361 nullptr, D->getLocStart());
7362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7363 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7364 return Res;
7365}
7366
Alexey Bataev80909872015-07-02 11:25:17 +00007367template <typename Derived>
7368StmtResult
7369TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7370 DeclarationNameInfo DirName;
7371 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7372 D->getLocStart());
7373 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7374 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7375 return Res;
7376}
7377
Alexey Bataev49f6e782015-12-01 04:18:41 +00007378template <typename Derived>
7379StmtResult
7380TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7381 DeclarationNameInfo DirName;
7382 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7383 D->getLocStart());
7384 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7385 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7386 return Res;
7387}
7388
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007389template <typename Derived>
7390StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7391 OMPTaskLoopSimdDirective *D) {
7392 DeclarationNameInfo DirName;
7393 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7394 nullptr, D->getLocStart());
7395 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7396 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7397 return Res;
7398}
7399
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007400template <typename Derived>
7401StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7402 OMPDistributeDirective *D) {
7403 DeclarationNameInfo DirName;
7404 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7405 D->getLocStart());
7406 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7407 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7408 return Res;
7409}
7410
Alexander Musman64d33f12014-06-04 07:53:32 +00007411//===----------------------------------------------------------------------===//
7412// OpenMP clause transformation
7413//===----------------------------------------------------------------------===//
7414template <typename Derived>
7415OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007416 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7417 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007418 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007419 return getDerived().RebuildOMPIfClause(
7420 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7421 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007422}
7423
Alexander Musman64d33f12014-06-04 07:53:32 +00007424template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007425OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7426 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7427 if (Cond.isInvalid())
7428 return nullptr;
7429 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7430 C->getLParenLoc(), C->getLocEnd());
7431}
7432
7433template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007434OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007435TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7436 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7437 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007438 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007439 return getDerived().RebuildOMPNumThreadsClause(
7440 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007441}
7442
Alexey Bataev62c87d22014-03-21 04:51:18 +00007443template <typename Derived>
7444OMPClause *
7445TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7446 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7447 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007448 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007449 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007450 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007451}
7452
Alexander Musman8bd31e62014-05-27 15:12:19 +00007453template <typename Derived>
7454OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007455TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7456 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7457 if (E.isInvalid())
7458 return nullptr;
7459 return getDerived().RebuildOMPSimdlenClause(
7460 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7461}
7462
7463template <typename Derived>
7464OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007465TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7466 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7467 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007468 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007469 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007470 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007471}
7472
Alexander Musman64d33f12014-06-04 07:53:32 +00007473template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007474OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007475TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007476 return getDerived().RebuildOMPDefaultClause(
7477 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7478 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007479}
7480
Alexander Musman64d33f12014-06-04 07:53:32 +00007481template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007482OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007483TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007484 return getDerived().RebuildOMPProcBindClause(
7485 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7486 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007487}
7488
Alexander Musman64d33f12014-06-04 07:53:32 +00007489template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007490OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007491TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7492 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7493 if (E.isInvalid())
7494 return nullptr;
7495 return getDerived().RebuildOMPScheduleClause(
7496 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7497 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7498}
7499
7500template <typename Derived>
7501OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007502TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007503 ExprResult E;
7504 if (auto *Num = C->getNumForLoops()) {
7505 E = getDerived().TransformExpr(Num);
7506 if (E.isInvalid())
7507 return nullptr;
7508 }
7509 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7510 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007511}
7512
7513template <typename Derived>
7514OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007515TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7516 // No need to rebuild this clause, no template-dependent parameters.
7517 return C;
7518}
7519
7520template <typename Derived>
7521OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007522TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7523 // No need to rebuild this clause, no template-dependent parameters.
7524 return C;
7525}
7526
7527template <typename Derived>
7528OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007529TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7530 // No need to rebuild this clause, no template-dependent parameters.
7531 return C;
7532}
7533
7534template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007535OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7536 // No need to rebuild this clause, no template-dependent parameters.
7537 return C;
7538}
7539
7540template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007541OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7542 // No need to rebuild this clause, no template-dependent parameters.
7543 return C;
7544}
7545
7546template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007547OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007548TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7549 // No need to rebuild this clause, no template-dependent parameters.
7550 return C;
7551}
7552
7553template <typename Derived>
7554OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007555TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7556 // No need to rebuild this clause, no template-dependent parameters.
7557 return C;
7558}
7559
7560template <typename Derived>
7561OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007562TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7563 // No need to rebuild this clause, no template-dependent parameters.
7564 return C;
7565}
7566
7567template <typename Derived>
7568OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007569TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7570 // No need to rebuild this clause, no template-dependent parameters.
7571 return C;
7572}
7573
7574template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007575OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7576 // No need to rebuild this clause, no template-dependent parameters.
7577 return C;
7578}
7579
7580template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007581OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007582TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7583 // No need to rebuild this clause, no template-dependent parameters.
7584 return C;
7585}
7586
7587template <typename Derived>
7588OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007589TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007590 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007591 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007592 for (auto *VE : C->varlists()) {
7593 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007594 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007595 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007596 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007597 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007598 return getDerived().RebuildOMPPrivateClause(
7599 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007600}
7601
Alexander Musman64d33f12014-06-04 07:53:32 +00007602template <typename Derived>
7603OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7604 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007605 llvm::SmallVector<Expr *, 16> Vars;
7606 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007607 for (auto *VE : C->varlists()) {
7608 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007609 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007610 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007611 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007612 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007613 return getDerived().RebuildOMPFirstprivateClause(
7614 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007615}
7616
Alexander Musman64d33f12014-06-04 07:53:32 +00007617template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007618OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007619TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7620 llvm::SmallVector<Expr *, 16> Vars;
7621 Vars.reserve(C->varlist_size());
7622 for (auto *VE : C->varlists()) {
7623 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7624 if (EVar.isInvalid())
7625 return nullptr;
7626 Vars.push_back(EVar.get());
7627 }
7628 return getDerived().RebuildOMPLastprivateClause(
7629 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7630}
7631
7632template <typename Derived>
7633OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007634TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7635 llvm::SmallVector<Expr *, 16> Vars;
7636 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007637 for (auto *VE : C->varlists()) {
7638 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007639 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007640 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007641 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007642 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007643 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7644 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007645}
7646
Alexander Musman64d33f12014-06-04 07:53:32 +00007647template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007648OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007649TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7650 llvm::SmallVector<Expr *, 16> Vars;
7651 Vars.reserve(C->varlist_size());
7652 for (auto *VE : C->varlists()) {
7653 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7654 if (EVar.isInvalid())
7655 return nullptr;
7656 Vars.push_back(EVar.get());
7657 }
7658 CXXScopeSpec ReductionIdScopeSpec;
7659 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7660
7661 DeclarationNameInfo NameInfo = C->getNameInfo();
7662 if (NameInfo.getName()) {
7663 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7664 if (!NameInfo.getName())
7665 return nullptr;
7666 }
7667 return getDerived().RebuildOMPReductionClause(
7668 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7669 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7670}
7671
7672template <typename Derived>
7673OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007674TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7675 llvm::SmallVector<Expr *, 16> Vars;
7676 Vars.reserve(C->varlist_size());
7677 for (auto *VE : C->varlists()) {
7678 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7679 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007680 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007681 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007682 }
7683 ExprResult Step = getDerived().TransformExpr(C->getStep());
7684 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007685 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007686 return getDerived().RebuildOMPLinearClause(
7687 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7688 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007689}
7690
Alexander Musman64d33f12014-06-04 07:53:32 +00007691template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007692OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007693TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7694 llvm::SmallVector<Expr *, 16> Vars;
7695 Vars.reserve(C->varlist_size());
7696 for (auto *VE : C->varlists()) {
7697 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7698 if (EVar.isInvalid())
7699 return nullptr;
7700 Vars.push_back(EVar.get());
7701 }
7702 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7703 if (Alignment.isInvalid())
7704 return nullptr;
7705 return getDerived().RebuildOMPAlignedClause(
7706 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7707 C->getColonLoc(), C->getLocEnd());
7708}
7709
Alexander Musman64d33f12014-06-04 07:53:32 +00007710template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007711OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007712TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7713 llvm::SmallVector<Expr *, 16> Vars;
7714 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007715 for (auto *VE : C->varlists()) {
7716 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007717 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007718 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007719 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007720 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007721 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7722 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007723}
7724
Alexey Bataevbae9a792014-06-27 10:37:06 +00007725template <typename Derived>
7726OMPClause *
7727TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7728 llvm::SmallVector<Expr *, 16> Vars;
7729 Vars.reserve(C->varlist_size());
7730 for (auto *VE : C->varlists()) {
7731 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7732 if (EVar.isInvalid())
7733 return nullptr;
7734 Vars.push_back(EVar.get());
7735 }
7736 return getDerived().RebuildOMPCopyprivateClause(
7737 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7738}
7739
Alexey Bataev6125da92014-07-21 11:26:11 +00007740template <typename Derived>
7741OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7742 llvm::SmallVector<Expr *, 16> Vars;
7743 Vars.reserve(C->varlist_size());
7744 for (auto *VE : C->varlists()) {
7745 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7746 if (EVar.isInvalid())
7747 return nullptr;
7748 Vars.push_back(EVar.get());
7749 }
7750 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7751 C->getLParenLoc(), C->getLocEnd());
7752}
7753
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007754template <typename Derived>
7755OMPClause *
7756TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7757 llvm::SmallVector<Expr *, 16> Vars;
7758 Vars.reserve(C->varlist_size());
7759 for (auto *VE : C->varlists()) {
7760 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7761 if (EVar.isInvalid())
7762 return nullptr;
7763 Vars.push_back(EVar.get());
7764 }
7765 return getDerived().RebuildOMPDependClause(
7766 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7767 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7768}
7769
Michael Wonge710d542015-08-07 16:16:36 +00007770template <typename Derived>
7771OMPClause *
7772TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7773 ExprResult E = getDerived().TransformExpr(C->getDevice());
7774 if (E.isInvalid())
7775 return nullptr;
7776 return getDerived().RebuildOMPDeviceClause(
7777 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7778}
7779
Kelvin Li0bff7af2015-11-23 05:32:03 +00007780template <typename Derived>
7781OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7782 llvm::SmallVector<Expr *, 16> Vars;
7783 Vars.reserve(C->varlist_size());
7784 for (auto *VE : C->varlists()) {
7785 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7786 if (EVar.isInvalid())
7787 return nullptr;
7788 Vars.push_back(EVar.get());
7789 }
7790 return getDerived().RebuildOMPMapClause(
7791 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7792 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7793 C->getLocEnd());
7794}
7795
Kelvin Li099bb8c2015-11-24 20:50:12 +00007796template <typename Derived>
7797OMPClause *
7798TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7799 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7800 if (E.isInvalid())
7801 return nullptr;
7802 return getDerived().RebuildOMPNumTeamsClause(
7803 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7804}
7805
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007806template <typename Derived>
7807OMPClause *
7808TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7809 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7810 if (E.isInvalid())
7811 return nullptr;
7812 return getDerived().RebuildOMPThreadLimitClause(
7813 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7814}
7815
Alexey Bataeva0569352015-12-01 10:17:31 +00007816template <typename Derived>
7817OMPClause *
7818TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7819 ExprResult E = getDerived().TransformExpr(C->getPriority());
7820 if (E.isInvalid())
7821 return nullptr;
7822 return getDerived().RebuildOMPPriorityClause(
7823 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7824}
7825
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00007826template <typename Derived>
7827OMPClause *
7828TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7829 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7830 if (E.isInvalid())
7831 return nullptr;
7832 return getDerived().RebuildOMPGrainsizeClause(
7833 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7834}
7835
Alexey Bataev382967a2015-12-08 12:06:20 +00007836template <typename Derived>
7837OMPClause *
7838TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7839 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7840 if (E.isInvalid())
7841 return nullptr;
7842 return getDerived().RebuildOMPNumTasksClause(
7843 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7844}
7845
Douglas Gregorebe10102009-08-20 07:17:43 +00007846//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007847// Expression transformation
7848//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007851TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007852 if (!E->isTypeDependent())
7853 return E;
7854
7855 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7856 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007857}
Mike Stump11289f42009-09-09 15:08:12 +00007858
7859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007860ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007861TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007862 NestedNameSpecifierLoc QualifierLoc;
7863 if (E->getQualifierLoc()) {
7864 QualifierLoc
7865 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7866 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007867 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007868 }
John McCallce546572009-12-08 09:08:17 +00007869
7870 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007871 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7872 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007875
John McCall815039a2010-08-17 21:27:17 +00007876 DeclarationNameInfo NameInfo = E->getNameInfo();
7877 if (NameInfo.getName()) {
7878 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7879 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007880 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007881 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007882
7883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007884 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007885 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007886 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007887 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007888
7889 // Mark it referenced in the new context regardless.
7890 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007891 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007892
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007893 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007894 }
John McCallce546572009-12-08 09:08:17 +00007895
Craig Topperc3ec1492014-05-26 06:22:03 +00007896 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007897 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007898 TemplateArgs = &TransArgs;
7899 TransArgs.setLAngleLoc(E->getLAngleLoc());
7900 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007901 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7902 E->getNumTemplateArgs(),
7903 TransArgs))
7904 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007905 }
7906
Chad Rosier1dcde962012-08-08 18:46:20 +00007907 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007908 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007909}
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007914 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007915}
Mike Stump11289f42009-09-09 15:08:12 +00007916
Douglas Gregora16548e2009-08-11 05:31:07 +00007917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007919TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007920 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007921}
Mike Stump11289f42009-09-09 15:08:12 +00007922
Douglas Gregora16548e2009-08-11 05:31:07 +00007923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007925TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007926 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007927}
Mike Stump11289f42009-09-09 15:08:12 +00007928
Douglas Gregora16548e2009-08-11 05:31:07 +00007929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007931TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007932 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007933}
Mike Stump11289f42009-09-09 15:08:12 +00007934
Douglas Gregora16548e2009-08-11 05:31:07 +00007935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007936ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007937TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007938 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007939}
7940
7941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007942ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007943TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007944 if (FunctionDecl *FD = E->getDirectCallee())
7945 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007946 return SemaRef.MaybeBindToTemporary(E);
7947}
7948
7949template<typename Derived>
7950ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007951TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7952 ExprResult ControllingExpr =
7953 getDerived().TransformExpr(E->getControllingExpr());
7954 if (ControllingExpr.isInvalid())
7955 return ExprError();
7956
Chris Lattner01cf8db2011-07-20 06:58:45 +00007957 SmallVector<Expr *, 4> AssocExprs;
7958 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007959 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7960 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7961 if (TS) {
7962 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7963 if (!AssocType)
7964 return ExprError();
7965 AssocTypes.push_back(AssocType);
7966 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007967 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007968 }
7969
7970 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7971 if (AssocExpr.isInvalid())
7972 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007973 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007974 }
7975
7976 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7977 E->getDefaultLoc(),
7978 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007979 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007980 AssocTypes,
7981 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007982}
7983
7984template<typename Derived>
7985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007986TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007987 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007988 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007990
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007992 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007993
John McCallb268a282010-08-23 23:25:46 +00007994 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 E->getRParen());
7996}
7997
Richard Smithdb2630f2012-10-21 03:28:35 +00007998/// \brief The operand of a unary address-of operator has special rules: it's
7999/// allowed to refer to a non-static member of a class even if there's no 'this'
8000/// object available.
8001template<typename Derived>
8002ExprResult
8003TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8004 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008005 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008006 else
8007 return getDerived().TransformExpr(E);
8008}
8009
Mike Stump11289f42009-09-09 15:08:12 +00008010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008012TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008013 ExprResult SubExpr;
8014 if (E->getOpcode() == UO_AddrOf)
8015 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8016 else
8017 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008020
Douglas Gregora16548e2009-08-11 05:31:07 +00008021 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008022 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008023
Douglas Gregora16548e2009-08-11 05:31:07 +00008024 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8025 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008026 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008027}
Mike Stump11289f42009-09-09 15:08:12 +00008028
Douglas Gregora16548e2009-08-11 05:31:07 +00008029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008030ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008031TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8032 // Transform the type.
8033 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8034 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008035 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008036
Douglas Gregor882211c2010-04-28 22:16:22 +00008037 // Transform all of the components into components similar to what the
8038 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008039 // FIXME: It would be slightly more efficient in the non-dependent case to
8040 // just map FieldDecls, rather than requiring the rebuilder to look for
8041 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008042 // template code that we don't care.
8043 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008044 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00008045 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008046 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008047 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8048 const Node &ON = E->getComponent(I);
8049 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008050 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008051 Comp.LocStart = ON.getSourceRange().getBegin();
8052 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008053 switch (ON.getKind()) {
8054 case Node::Array: {
8055 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008056 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008057 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008058 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008059
Douglas Gregor882211c2010-04-28 22:16:22 +00008060 ExprChanged = ExprChanged || Index.get() != FromIndex;
8061 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008062 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008063 break;
8064 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008065
Douglas Gregor882211c2010-04-28 22:16:22 +00008066 case Node::Field:
8067 case Node::Identifier:
8068 Comp.isBrackets = false;
8069 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008070 if (!Comp.U.IdentInfo)
8071 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008072
Douglas Gregor882211c2010-04-28 22:16:22 +00008073 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008074
Douglas Gregord1702062010-04-29 00:18:15 +00008075 case Node::Base:
8076 // Will be recomputed during the rebuild.
8077 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008079
Douglas Gregor882211c2010-04-28 22:16:22 +00008080 Components.push_back(Comp);
8081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008082
Douglas Gregor882211c2010-04-28 22:16:22 +00008083 // If nothing changed, retain the existing expression.
8084 if (!getDerived().AlwaysRebuild() &&
8085 Type == E->getTypeSourceInfo() &&
8086 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008087 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008088
Douglas Gregor882211c2010-04-28 22:16:22 +00008089 // Build a new offsetof expression.
8090 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008091 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008092}
8093
8094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008096TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008097 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008098 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008099 return E;
John McCall8d69a212010-11-15 23:31:06 +00008100}
8101
8102template<typename Derived>
8103ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008104TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8105 return E;
8106}
8107
8108template<typename Derived>
8109ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008110TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008111 // Rebuild the syntactic form. The original syntactic form has
8112 // opaque-value expressions in it, so strip those away and rebuild
8113 // the result. This is a really awful way of doing this, but the
8114 // better solution (rebuilding the semantic expressions and
8115 // rebinding OVEs as necessary) doesn't work; we'd need
8116 // TreeTransform to not strip away implicit conversions.
8117 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8118 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008119 if (result.isInvalid()) return ExprError();
8120
8121 // If that gives us a pseudo-object result back, the pseudo-object
8122 // expression must have been an lvalue-to-rvalue conversion which we
8123 // should reapply.
8124 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008125 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008126
8127 return result;
8128}
8129
8130template<typename Derived>
8131ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008132TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8133 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008135 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008136
John McCallbcd03502009-12-07 02:54:59 +00008137 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008138 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008140
John McCall4c98fd82009-11-04 07:28:41 +00008141 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008142 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008143
Peter Collingbournee190dee2011-03-11 19:24:49 +00008144 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8145 E->getKind(),
8146 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008147 }
Mike Stump11289f42009-09-09 15:08:12 +00008148
Eli Friedmane4f22df2012-02-29 04:03:55 +00008149 // C++0x [expr.sizeof]p1:
8150 // The operand is either an expression, which is an unevaluated operand
8151 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008152 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8153 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008154
Reid Kleckner32506ed2014-06-12 23:03:48 +00008155 // Try to recover if we have something like sizeof(T::X) where X is a type.
8156 // Notably, there must be *exactly* one set of parens if X is a type.
8157 TypeSourceInfo *RecoveryTSI = nullptr;
8158 ExprResult SubExpr;
8159 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8160 if (auto *DRE =
8161 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8162 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8163 PE, DRE, false, &RecoveryTSI);
8164 else
8165 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8166
8167 if (RecoveryTSI) {
8168 return getDerived().RebuildUnaryExprOrTypeTrait(
8169 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8170 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008172
Eli Friedmane4f22df2012-02-29 04:03:55 +00008173 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008175
Peter Collingbournee190dee2011-03-11 19:24:49 +00008176 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8177 E->getOperatorLoc(),
8178 E->getKind(),
8179 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008180}
Mike Stump11289f42009-09-09 15:08:12 +00008181
Douglas Gregora16548e2009-08-11 05:31:07 +00008182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008184TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008185 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008188
John McCalldadc5752010-08-24 06:29:42 +00008189 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008192
8193
Douglas Gregora16548e2009-08-11 05:31:07 +00008194 if (!getDerived().AlwaysRebuild() &&
8195 LHS.get() == E->getLHS() &&
8196 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008197 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008198
John McCallb268a282010-08-23 23:25:46 +00008199 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008201 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008202 E->getRBracketLoc());
8203}
Mike Stump11289f42009-09-09 15:08:12 +00008204
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008205template <typename Derived>
8206ExprResult
8207TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8208 ExprResult Base = getDerived().TransformExpr(E->getBase());
8209 if (Base.isInvalid())
8210 return ExprError();
8211
8212 ExprResult LowerBound;
8213 if (E->getLowerBound()) {
8214 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8215 if (LowerBound.isInvalid())
8216 return ExprError();
8217 }
8218
8219 ExprResult Length;
8220 if (E->getLength()) {
8221 Length = getDerived().TransformExpr(E->getLength());
8222 if (Length.isInvalid())
8223 return ExprError();
8224 }
8225
8226 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8227 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8228 return E;
8229
8230 return getDerived().RebuildOMPArraySectionExpr(
8231 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8232 Length.get(), E->getRBracketLoc());
8233}
8234
Mike Stump11289f42009-09-09 15:08:12 +00008235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008237TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008238 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008239 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008240 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008241 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008242
8243 // Transform arguments.
8244 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008245 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008246 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008247 &ArgChanged))
8248 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008249
Douglas Gregora16548e2009-08-11 05:31:07 +00008250 if (!getDerived().AlwaysRebuild() &&
8251 Callee.get() == E->getCallee() &&
8252 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008253 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008256 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008257 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008258 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008259 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008260 E->getRParenLoc());
8261}
Mike Stump11289f42009-09-09 15:08:12 +00008262
8263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008265TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008266 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008267 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008269
Douglas Gregorea972d32011-02-28 21:54:11 +00008270 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008271 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008272 QualifierLoc
8273 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008274
Douglas Gregorea972d32011-02-28 21:54:11 +00008275 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008276 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008277 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008278 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008279
Eli Friedman2cfcef62009-12-04 06:40:45 +00008280 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008281 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8282 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008283 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008285
John McCall16df1e52010-03-30 21:47:33 +00008286 NamedDecl *FoundDecl = E->getFoundDecl();
8287 if (FoundDecl == E->getMemberDecl()) {
8288 FoundDecl = Member;
8289 } else {
8290 FoundDecl = cast_or_null<NamedDecl>(
8291 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8292 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008294 }
8295
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 if (!getDerived().AlwaysRebuild() &&
8297 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008298 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008299 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008300 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008301 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008302
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008303 // Mark it referenced in the new context regardless.
8304 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008305 SemaRef.MarkMemberReferenced(E);
8306
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008307 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008308 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008309
John McCall6b51f282009-11-23 01:53:49 +00008310 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008311 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008312 TransArgs.setLAngleLoc(E->getLAngleLoc());
8313 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008314 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8315 E->getNumTemplateArgs(),
8316 TransArgs))
8317 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008318 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008319
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008321 SourceLocation FakeOperatorLoc =
8322 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008323
John McCall38836f02010-01-15 08:34:02 +00008324 // FIXME: to do this check properly, we will need to preserve the
8325 // first-qualifier-in-scope here, just in case we had a dependent
8326 // base (and therefore couldn't do the check) and a
8327 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008328 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008329
John McCallb268a282010-08-23 23:25:46 +00008330 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008332 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008333 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008334 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008335 Member,
John McCall16df1e52010-03-30 21:47:33 +00008336 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008337 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008338 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008339 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008340}
Mike Stump11289f42009-09-09 15:08:12 +00008341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008344TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008345 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008348
John McCalldadc5752010-08-24 06:29:42 +00008349 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008352
Douglas Gregora16548e2009-08-11 05:31:07 +00008353 if (!getDerived().AlwaysRebuild() &&
8354 LHS.get() == E->getLHS() &&
8355 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008356 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008357
Lang Hames5de91cc2012-10-02 04:45:10 +00008358 Sema::FPContractStateRAII FPContractState(getSema());
8359 getSema().FPFeatures.fp_contract = E->isFPContractable();
8360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008362 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008363}
8364
Mike Stump11289f42009-09-09 15:08:12 +00008365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008366ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008367TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008368 CompoundAssignOperator *E) {
8369 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008370}
Mike Stump11289f42009-09-09 15:08:12 +00008371
Douglas Gregora16548e2009-08-11 05:31:07 +00008372template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008373ExprResult TreeTransform<Derived>::
8374TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8375 // Just rebuild the common and RHS expressions and see whether we
8376 // get any changes.
8377
8378 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8379 if (commonExpr.isInvalid())
8380 return ExprError();
8381
8382 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8383 if (rhs.isInvalid())
8384 return ExprError();
8385
8386 if (!getDerived().AlwaysRebuild() &&
8387 commonExpr.get() == e->getCommon() &&
8388 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008389 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008390
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008391 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008392 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008393 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008394 e->getColonLoc(),
8395 rhs.get());
8396}
8397
8398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008400TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008401 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008402 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008404
John McCalldadc5752010-08-24 06:29:42 +00008405 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008406 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008408
John McCalldadc5752010-08-24 06:29:42 +00008409 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008412
Douglas Gregora16548e2009-08-11 05:31:07 +00008413 if (!getDerived().AlwaysRebuild() &&
8414 Cond.get() == E->getCond() &&
8415 LHS.get() == E->getLHS() &&
8416 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008417 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008418
John McCallb268a282010-08-23 23:25:46 +00008419 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008420 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008421 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008422 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008423 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008424}
Mike Stump11289f42009-09-09 15:08:12 +00008425
8426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008428TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008429 // Implicit casts are eliminated during transformation, since they
8430 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008431 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008432}
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregora16548e2009-08-11 05:31:07 +00008434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008436TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008437 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8438 if (!Type)
8439 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008440
John McCalldadc5752010-08-24 06:29:42 +00008441 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008442 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008445
Douglas Gregora16548e2009-08-11 05:31:07 +00008446 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008447 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008449 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008450
John McCall97513962010-01-15 18:39:57 +00008451 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008452 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008453 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008454 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008455}
Mike Stump11289f42009-09-09 15:08:12 +00008456
Douglas Gregora16548e2009-08-11 05:31:07 +00008457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008459TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008460 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8461 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8462 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008464
John McCalldadc5752010-08-24 06:29:42 +00008465 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008466 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008468
Douglas Gregora16548e2009-08-11 05:31:07 +00008469 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008470 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008471 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008472 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008473
John McCall5d7aa7f2010-01-19 22:33:45 +00008474 // Note: the expression type doesn't necessarily match the
8475 // type-as-written, but that's okay, because it should always be
8476 // derivable from the initializer.
8477
John McCalle15bbff2010-01-18 19:35:47 +00008478 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008479 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008480 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008481}
Mike Stump11289f42009-09-09 15:08:12 +00008482
Douglas Gregora16548e2009-08-11 05:31:07 +00008483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008485TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008486 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008487 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008489
Douglas Gregora16548e2009-08-11 05:31:07 +00008490 if (!getDerived().AlwaysRebuild() &&
8491 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008492 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008493
Douglas Gregora16548e2009-08-11 05:31:07 +00008494 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008495 SourceLocation FakeOperatorLoc =
8496 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008497 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008498 E->getAccessorLoc(),
8499 E->getAccessor());
8500}
Mike Stump11289f42009-09-09 15:08:12 +00008501
Douglas Gregora16548e2009-08-11 05:31:07 +00008502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008504TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008505 if (InitListExpr *Syntactic = E->getSyntacticForm())
8506 E = Syntactic;
8507
Douglas Gregora16548e2009-08-11 05:31:07 +00008508 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008509
Benjamin Kramerf0623432012-08-23 22:51:59 +00008510 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008511 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008512 Inits, &InitChanged))
8513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008514
Richard Smith520449d2015-02-05 06:15:50 +00008515 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8516 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8517 // in some cases. We can't reuse it in general, because the syntactic and
8518 // semantic forms are linked, and we can't know that semantic form will
8519 // match even if the syntactic form does.
8520 }
Mike Stump11289f42009-09-09 15:08:12 +00008521
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008522 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008523 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008524}
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008528TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008530
Douglas Gregorebe10102009-08-20 07:17:43 +00008531 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008532 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregorebe10102009-08-20 07:17:43 +00008536 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008537 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 bool ExprChanged = false;
8539 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8540 DEnd = E->designators_end();
8541 D != DEnd; ++D) {
8542 if (D->isFieldDesignator()) {
8543 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8544 D->getDotLoc(),
8545 D->getFieldLoc()));
8546 continue;
8547 }
Mike Stump11289f42009-09-09 15:08:12 +00008548
Douglas Gregora16548e2009-08-11 05:31:07 +00008549 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008550 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008553
8554 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008555 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008556
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008558 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 continue;
8560 }
Mike Stump11289f42009-09-09 15:08:12 +00008561
Douglas Gregora16548e2009-08-11 05:31:07 +00008562 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008563 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8565 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008567
John McCalldadc5752010-08-24 06:29:42 +00008568 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008571
8572 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008573 End.get(),
8574 D->getLBracketLoc(),
8575 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008576
Douglas Gregora16548e2009-08-11 05:31:07 +00008577 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8578 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008579
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008580 ArrayExprs.push_back(Start.get());
8581 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008582 }
Mike Stump11289f42009-09-09 15:08:12 +00008583
Douglas Gregora16548e2009-08-11 05:31:07 +00008584 if (!getDerived().AlwaysRebuild() &&
8585 Init.get() == E->getInit() &&
8586 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008587 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008588
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008589 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008591 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008592}
Mike Stump11289f42009-09-09 15:08:12 +00008593
Yunzhong Gaocb779302015-06-10 00:27:52 +00008594// Seems that if TransformInitListExpr() only works on the syntactic form of an
8595// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8596template<typename Derived>
8597ExprResult
8598TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8599 DesignatedInitUpdateExpr *E) {
8600 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8601 "initializer");
8602 return ExprError();
8603}
8604
8605template<typename Derived>
8606ExprResult
8607TreeTransform<Derived>::TransformNoInitExpr(
8608 NoInitExpr *E) {
8609 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8610 return ExprError();
8611}
8612
Douglas Gregora16548e2009-08-11 05:31:07 +00008613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008614ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008615TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008616 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008617 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008618
Douglas Gregor3da3c062009-10-28 00:29:27 +00008619 // FIXME: Will we ever have proper type location here? Will we actually
8620 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008621 QualType T = getDerived().TransformType(E->getType());
8622 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008624
Douglas Gregora16548e2009-08-11 05:31:07 +00008625 if (!getDerived().AlwaysRebuild() &&
8626 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008627 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008628
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 return getDerived().RebuildImplicitValueInitExpr(T);
8630}
Mike Stump11289f42009-09-09 15:08:12 +00008631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008633ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008634TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008635 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8636 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008638
John McCalldadc5752010-08-24 06:29:42 +00008639 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008640 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008642
Douglas Gregora16548e2009-08-11 05:31:07 +00008643 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008644 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008645 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008646 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008647
John McCallb268a282010-08-23 23:25:46 +00008648 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008649 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008650}
8651
8652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008654TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008655 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008656 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008657 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8658 &ArgumentChanged))
8659 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008660
Douglas Gregora16548e2009-08-11 05:31:07 +00008661 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008662 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008663 E->getRParenLoc());
8664}
Mike Stump11289f42009-09-09 15:08:12 +00008665
Douglas Gregora16548e2009-08-11 05:31:07 +00008666/// \brief Transform an address-of-label expression.
8667///
8668/// By default, the transformation of an address-of-label expression always
8669/// rebuilds the expression, so that the label identifier can be resolved to
8670/// the corresponding label statement by semantic analysis.
8671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008673TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008674 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8675 E->getLabel());
8676 if (!LD)
8677 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008678
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008680 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008681}
Mike Stump11289f42009-09-09 15:08:12 +00008682
8683template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008685TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008686 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008687 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008688 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008689 if (SubStmt.isInvalid()) {
8690 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008691 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008692 }
Mike Stump11289f42009-09-09 15:08:12 +00008693
Douglas Gregora16548e2009-08-11 05:31:07 +00008694 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008695 SubStmt.get() == E->getSubStmt()) {
8696 // Calling this an 'error' is unintuitive, but it does the right thing.
8697 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008698 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008699 }
Mike Stump11289f42009-09-09 15:08:12 +00008700
8701 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008702 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008703 E->getRParenLoc());
8704}
Mike Stump11289f42009-09-09 15:08:12 +00008705
Douglas Gregora16548e2009-08-11 05:31:07 +00008706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008707ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008708TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008709 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008712
John McCalldadc5752010-08-24 06:29:42 +00008713 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008714 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008716
John McCalldadc5752010-08-24 06:29:42 +00008717 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008718 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008720
Douglas Gregora16548e2009-08-11 05:31:07 +00008721 if (!getDerived().AlwaysRebuild() &&
8722 Cond.get() == E->getCond() &&
8723 LHS.get() == E->getLHS() &&
8724 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008725 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008726
Douglas Gregora16548e2009-08-11 05:31:07 +00008727 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008728 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008729 E->getRParenLoc());
8730}
Mike Stump11289f42009-09-09 15:08:12 +00008731
Douglas Gregora16548e2009-08-11 05:31:07 +00008732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008734TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008735 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008736}
8737
8738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008740TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008741 switch (E->getOperator()) {
8742 case OO_New:
8743 case OO_Delete:
8744 case OO_Array_New:
8745 case OO_Array_Delete:
8746 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008747
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008748 case OO_Call: {
8749 // This is a call to an object's operator().
8750 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8751
8752 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008753 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008754 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008755 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008756
8757 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008758 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8759 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008760
8761 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008762 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008763 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008764 Args))
8765 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008766
John McCallb268a282010-08-23 23:25:46 +00008767 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008768 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008769 E->getLocEnd());
8770 }
8771
8772#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8773 case OO_##Name:
8774#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8775#include "clang/Basic/OperatorKinds.def"
8776 case OO_Subscript:
8777 // Handled below.
8778 break;
8779
8780 case OO_Conditional:
8781 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008782
8783 case OO_None:
8784 case NUM_OVERLOADED_OPERATORS:
8785 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008786 }
8787
John McCalldadc5752010-08-24 06:29:42 +00008788 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008789 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008791
Richard Smithdb2630f2012-10-21 03:28:35 +00008792 ExprResult First;
8793 if (E->getOperator() == OO_Amp)
8794 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8795 else
8796 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008797 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008798 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008799
John McCalldadc5752010-08-24 06:29:42 +00008800 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008801 if (E->getNumArgs() == 2) {
8802 Second = getDerived().TransformExpr(E->getArg(1));
8803 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008804 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 }
Mike Stump11289f42009-09-09 15:08:12 +00008806
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 if (!getDerived().AlwaysRebuild() &&
8808 Callee.get() == E->getCallee() &&
8809 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008810 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008811 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008812
Lang Hames5de91cc2012-10-02 04:45:10 +00008813 Sema::FPContractStateRAII FPContractState(getSema());
8814 getSema().FPFeatures.fp_contract = E->isFPContractable();
8815
Douglas Gregora16548e2009-08-11 05:31:07 +00008816 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8817 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008818 Callee.get(),
8819 First.get(),
8820 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008821}
Mike Stump11289f42009-09-09 15:08:12 +00008822
Douglas Gregora16548e2009-08-11 05:31:07 +00008823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008825TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8826 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008827}
Mike Stump11289f42009-09-09 15:08:12 +00008828
Douglas Gregora16548e2009-08-11 05:31:07 +00008829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008830ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008831TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8832 // Transform the callee.
8833 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8834 if (Callee.isInvalid())
8835 return ExprError();
8836
8837 // Transform exec config.
8838 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8839 if (EC.isInvalid())
8840 return ExprError();
8841
8842 // Transform arguments.
8843 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008844 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008845 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008846 &ArgChanged))
8847 return ExprError();
8848
8849 if (!getDerived().AlwaysRebuild() &&
8850 Callee.get() == E->getCallee() &&
8851 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008852 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008853
8854 // FIXME: Wrong source location information for the '('.
8855 SourceLocation FakeLParenLoc
8856 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8857 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008858 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008859 E->getRParenLoc(), EC.get());
8860}
8861
8862template<typename Derived>
8863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008864TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008865 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8866 if (!Type)
8867 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008868
John McCalldadc5752010-08-24 06:29:42 +00008869 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008870 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008871 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008873
Douglas Gregora16548e2009-08-11 05:31:07 +00008874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008875 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008876 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008877 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008878 return getDerived().RebuildCXXNamedCastExpr(
8879 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8880 Type, E->getAngleBrackets().getEnd(),
8881 // FIXME. this should be '(' location
8882 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008883}
Mike Stump11289f42009-09-09 15:08:12 +00008884
Douglas Gregora16548e2009-08-11 05:31:07 +00008885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008887TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8888 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008889}
Mike Stump11289f42009-09-09 15:08:12 +00008890
8891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008893TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8894 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008895}
8896
Douglas Gregora16548e2009-08-11 05:31:07 +00008897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008898ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008899TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008900 CXXReinterpretCastExpr *E) {
8901 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008902}
Mike Stump11289f42009-09-09 15:08:12 +00008903
Douglas Gregora16548e2009-08-11 05:31:07 +00008904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008906TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8907 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
Douglas Gregora16548e2009-08-11 05:31:07 +00008910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008911ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008912TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008913 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008914 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8915 if (!Type)
8916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008917
John McCalldadc5752010-08-24 06:29:42 +00008918 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008919 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008920 if (SubExpr.isInvalid())
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() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008924 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008925 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008926 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008927
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008928 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008929 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008930 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008931 E->getRParenLoc());
8932}
Mike Stump11289f42009-09-09 15:08:12 +00008933
Douglas Gregora16548e2009-08-11 05:31:07 +00008934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008936TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008937 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008938 TypeSourceInfo *TInfo
8939 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8940 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008941 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008942
Douglas Gregora16548e2009-08-11 05:31:07 +00008943 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008944 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008945 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008946
Douglas Gregor9da64192010-04-26 22:37:10 +00008947 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8948 E->getLocStart(),
8949 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008950 E->getLocEnd());
8951 }
Mike Stump11289f42009-09-09 15:08:12 +00008952
Eli Friedman456f0182012-01-20 01:26:23 +00008953 // We don't know whether the subexpression is potentially evaluated until
8954 // after we perform semantic analysis. We speculatively assume it is
8955 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008957 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8958 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008959
John McCalldadc5752010-08-24 06:29:42 +00008960 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008961 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008963
Douglas Gregora16548e2009-08-11 05:31:07 +00008964 if (!getDerived().AlwaysRebuild() &&
8965 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008966 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008967
Douglas Gregor9da64192010-04-26 22:37:10 +00008968 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8969 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008970 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008971 E->getLocEnd());
8972}
8973
8974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008975ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008976TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8977 if (E->isTypeOperand()) {
8978 TypeSourceInfo *TInfo
8979 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8980 if (!TInfo)
8981 return ExprError();
8982
8983 if (!getDerived().AlwaysRebuild() &&
8984 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008985 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008986
Douglas Gregor69735112011-03-06 17:40:41 +00008987 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008988 E->getLocStart(),
8989 TInfo,
8990 E->getLocEnd());
8991 }
8992
Francois Pichet9f4f2072010-09-08 12:20:18 +00008993 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8994
8995 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8996 if (SubExpr.isInvalid())
8997 return ExprError();
8998
8999 if (!getDerived().AlwaysRebuild() &&
9000 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009001 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009002
9003 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9004 E->getLocStart(),
9005 SubExpr.get(),
9006 E->getLocEnd());
9007}
9008
9009template<typename Derived>
9010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009011TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009012 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009013}
Mike Stump11289f42009-09-09 15:08:12 +00009014
Douglas Gregora16548e2009-08-11 05:31:07 +00009015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009016ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009017TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009018 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009019 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009020}
Mike Stump11289f42009-09-09 15:08:12 +00009021
Douglas Gregora16548e2009-08-11 05:31:07 +00009022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009024TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009025 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009026
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009027 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9028 // Make sure that we capture 'this'.
9029 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009030 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009032
Douglas Gregorb15af892010-01-07 23:12:05 +00009033 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009034}
Mike Stump11289f42009-09-09 15:08:12 +00009035
Douglas Gregora16548e2009-08-11 05:31:07 +00009036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009038TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009039 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009040 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009042
Douglas Gregora16548e2009-08-11 05:31:07 +00009043 if (!getDerived().AlwaysRebuild() &&
9044 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009045 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009046
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009047 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9048 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009049}
Mike Stump11289f42009-09-09 15:08:12 +00009050
Douglas Gregora16548e2009-08-11 05:31:07 +00009051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009053TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009054 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009055 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9056 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009057 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009059
Chandler Carruth794da4c2010-02-08 06:42:49 +00009060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009061 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009062 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregor033f6752009-12-23 23:03:06 +00009064 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009065}
Mike Stump11289f42009-09-09 15:08:12 +00009066
Douglas Gregora16548e2009-08-11 05:31:07 +00009067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009068ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009069TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9070 FieldDecl *Field
9071 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9072 E->getField()));
9073 if (!Field)
9074 return ExprError();
9075
9076 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009077 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009078
9079 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9080}
9081
9082template<typename Derived>
9083ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009084TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9085 CXXScalarValueInitExpr *E) {
9086 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9087 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009088 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009089
Douglas Gregora16548e2009-08-11 05:31:07 +00009090 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009091 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009092 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009093
Chad Rosier1dcde962012-08-08 18:46:20 +00009094 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009095 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009096 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009097}
Mike Stump11289f42009-09-09 15:08:12 +00009098
Douglas Gregora16548e2009-08-11 05:31:07 +00009099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009101TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009102 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009103 TypeSourceInfo *AllocTypeInfo
9104 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9105 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009107
Douglas Gregora16548e2009-08-11 05:31:07 +00009108 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009109 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009110 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 // Transform the placement arguments (if any).
9114 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009115 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009116 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009117 E->getNumPlacementArgs(), true,
9118 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009120
Sebastian Redl6047f072012-02-16 12:22:20 +00009121 // Transform the initializer (if any).
9122 Expr *OldInit = E->getInitializer();
9123 ExprResult NewInit;
9124 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009125 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009126 if (NewInit.isInvalid())
9127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009128
Sebastian Redl6047f072012-02-16 12:22:20 +00009129 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009130 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009131 if (E->getOperatorNew()) {
9132 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009133 getDerived().TransformDecl(E->getLocStart(),
9134 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009135 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009136 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009137 }
9138
Craig Topperc3ec1492014-05-26 06:22:03 +00009139 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009140 if (E->getOperatorDelete()) {
9141 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009142 getDerived().TransformDecl(E->getLocStart(),
9143 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009144 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009145 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009147
Douglas Gregora16548e2009-08-11 05:31:07 +00009148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009149 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009151 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009152 OperatorNew == E->getOperatorNew() &&
9153 OperatorDelete == E->getOperatorDelete() &&
9154 !ArgumentChanged) {
9155 // Mark any declarations we need as referenced.
9156 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009157 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009158 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009159 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009160 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009161
Sebastian Redl6047f072012-02-16 12:22:20 +00009162 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009163 QualType ElementType
9164 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9165 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9166 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9167 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009168 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009169 }
9170 }
9171 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009172
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009173 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009174 }
Mike Stump11289f42009-09-09 15:08:12 +00009175
Douglas Gregor0744ef62010-09-07 21:49:58 +00009176 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009177 if (!ArraySize.get()) {
9178 // If no array size was specified, but the new expression was
9179 // instantiated with an array type (e.g., "new T" where T is
9180 // instantiated with "int[4]"), extract the outer bound from the
9181 // array type as our array size. We do this with constant and
9182 // dependently-sized array types.
9183 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9184 if (!ArrayT) {
9185 // Do nothing
9186 } else if (const ConstantArrayType *ConsArrayT
9187 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009188 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9189 SemaRef.Context.getSizeType(),
9190 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009191 AllocType = ConsArrayT->getElementType();
9192 } else if (const DependentSizedArrayType *DepArrayT
9193 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9194 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009195 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009196 AllocType = DepArrayT->getElementType();
9197 }
9198 }
9199 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009200
Douglas Gregora16548e2009-08-11 05:31:07 +00009201 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9202 E->isGlobalNew(),
9203 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009204 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009205 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009206 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009207 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009208 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009209 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009210 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009211 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009212}
Mike Stump11289f42009-09-09 15:08:12 +00009213
Douglas Gregora16548e2009-08-11 05:31:07 +00009214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009216TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009217 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009218 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009220
Douglas Gregord2d9da02010-02-26 00:38:10 +00009221 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009222 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009223 if (E->getOperatorDelete()) {
9224 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009225 getDerived().TransformDecl(E->getLocStart(),
9226 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009227 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009228 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009230
Douglas Gregora16548e2009-08-11 05:31:07 +00009231 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009232 Operand.get() == E->getArgument() &&
9233 OperatorDelete == E->getOperatorDelete()) {
9234 // Mark any declarations we need as referenced.
9235 // FIXME: instantiation-specific.
9236 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009237 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009238
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009239 if (!E->getArgument()->isTypeDependent()) {
9240 QualType Destroyed = SemaRef.Context.getBaseElementType(
9241 E->getDestroyedType());
9242 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9243 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009244 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009245 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009246 }
9247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009248
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009249 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009250 }
Mike Stump11289f42009-09-09 15:08:12 +00009251
Douglas Gregora16548e2009-08-11 05:31:07 +00009252 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9253 E->isGlobalDelete(),
9254 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009255 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009256}
Mike Stump11289f42009-09-09 15:08:12 +00009257
Douglas Gregora16548e2009-08-11 05:31:07 +00009258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009259ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009260TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009261 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009262 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009263 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009265
John McCallba7bf592010-08-24 05:47:05 +00009266 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009267 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009268 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009269 E->getOperatorLoc(),
9270 E->isArrow()? tok::arrow : tok::period,
9271 ObjectTypePtr,
9272 MayBePseudoDestructor);
9273 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009274 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009275
John McCallba7bf592010-08-24 05:47:05 +00009276 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009277 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9278 if (QualifierLoc) {
9279 QualifierLoc
9280 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9281 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009282 return ExprError();
9283 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009284 CXXScopeSpec SS;
9285 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009286
Douglas Gregor678f90d2010-02-25 01:56:36 +00009287 PseudoDestructorTypeStorage Destroyed;
9288 if (E->getDestroyedTypeInfo()) {
9289 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009290 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009291 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009292 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009293 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009294 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009295 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009296 // We aren't likely to be able to resolve the identifier down to a type
9297 // now anyway, so just retain the identifier.
9298 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9299 E->getDestroyedTypeLoc());
9300 } else {
9301 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009302 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009303 *E->getDestroyedTypeIdentifier(),
9304 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009305 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009306 SS, ObjectTypePtr,
9307 false);
9308 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009309 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregor678f90d2010-02-25 01:56:36 +00009311 Destroyed
9312 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9313 E->getDestroyedTypeLoc());
9314 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009315
Craig Topperc3ec1492014-05-26 06:22:03 +00009316 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009317 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009318 CXXScopeSpec EmptySS;
9319 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009320 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009321 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009322 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009324
John McCallb268a282010-08-23 23:25:46 +00009325 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009326 E->getOperatorLoc(),
9327 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009328 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009329 ScopeTypeInfo,
9330 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009331 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009332 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009333}
Mike Stump11289f42009-09-09 15:08:12 +00009334
Douglas Gregorad8a3362009-09-04 17:36:40 +00009335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009336ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009337TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009338 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009339 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9340 Sema::LookupOrdinaryName);
9341
9342 // Transform all the decls.
9343 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9344 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009345 NamedDecl *InstD = static_cast<NamedDecl*>(
9346 getDerived().TransformDecl(Old->getNameLoc(),
9347 *I));
John McCall84d87672009-12-10 09:41:52 +00009348 if (!InstD) {
9349 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9350 // This can happen because of dependent hiding.
9351 if (isa<UsingShadowDecl>(*I))
9352 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009353 else {
9354 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009355 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009356 }
John McCall84d87672009-12-10 09:41:52 +00009357 }
John McCalle66edc12009-11-24 19:00:30 +00009358
9359 // Expand using declarations.
9360 if (isa<UsingDecl>(InstD)) {
9361 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009362 for (auto *I : UD->shadows())
9363 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009364 continue;
9365 }
9366
9367 R.addDecl(InstD);
9368 }
9369
9370 // Resolve a kind, but don't do any further analysis. If it's
9371 // ambiguous, the callee needs to deal with it.
9372 R.resolveKind();
9373
9374 // Rebuild the nested-name qualifier, if present.
9375 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009376 if (Old->getQualifierLoc()) {
9377 NestedNameSpecifierLoc QualifierLoc
9378 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9379 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009380 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009381
Douglas Gregor0da1d432011-02-28 20:01:57 +00009382 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009383 }
9384
Douglas Gregor9262f472010-04-27 18:19:34 +00009385 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009386 CXXRecordDecl *NamingClass
9387 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9388 Old->getNameLoc(),
9389 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009390 if (!NamingClass) {
9391 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009392 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009394
Douglas Gregorda7be082010-04-27 16:10:10 +00009395 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009396 }
9397
Abramo Bagnara7945c982012-01-27 09:46:47 +00009398 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9399
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009400 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009401 // it's a normal declaration name or member reference.
9402 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9403 NamedDecl *D = R.getAsSingle<NamedDecl>();
9404 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9405 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9406 // give a good diagnostic.
9407 if (D && D->isCXXInstanceMember()) {
9408 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9409 /*TemplateArgs=*/nullptr,
9410 /*Scope=*/nullptr);
9411 }
9412
John McCalle66edc12009-11-24 19:00:30 +00009413 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009414 }
John McCalle66edc12009-11-24 19:00:30 +00009415
9416 // If we have template arguments, rebuild them, then rebuild the
9417 // templateid expression.
9418 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009419 if (Old->hasExplicitTemplateArgs() &&
9420 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009421 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009422 TransArgs)) {
9423 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009424 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009425 }
John McCalle66edc12009-11-24 19:00:30 +00009426
Abramo Bagnara7945c982012-01-27 09:46:47 +00009427 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009428 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009429}
Mike Stump11289f42009-09-09 15:08:12 +00009430
Douglas Gregora16548e2009-08-11 05:31:07 +00009431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009432ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009433TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9434 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009435 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009436 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9437 TypeSourceInfo *From = E->getArg(I);
9438 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009439 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009440 TypeLocBuilder TLB;
9441 TLB.reserve(FromTL.getFullDataSize());
9442 QualType To = getDerived().TransformType(TLB, FromTL);
9443 if (To.isNull())
9444 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009445
Douglas Gregor29c42f22012-02-24 07:38:34 +00009446 if (To == From->getType())
9447 Args.push_back(From);
9448 else {
9449 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9450 ArgChanged = true;
9451 }
9452 continue;
9453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009454
Douglas Gregor29c42f22012-02-24 07:38:34 +00009455 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009456
Douglas Gregor29c42f22012-02-24 07:38:34 +00009457 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009458 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009459 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9460 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9461 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009462
Douglas Gregor29c42f22012-02-24 07:38:34 +00009463 // Determine whether the set of unexpanded parameter packs can and should
9464 // be expanded.
9465 bool Expand = true;
9466 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009467 Optional<unsigned> OrigNumExpansions =
9468 ExpansionTL.getTypePtr()->getNumExpansions();
9469 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009470 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9471 PatternTL.getSourceRange(),
9472 Unexpanded,
9473 Expand, RetainExpansion,
9474 NumExpansions))
9475 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009476
Douglas Gregor29c42f22012-02-24 07:38:34 +00009477 if (!Expand) {
9478 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009479 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009480 // expansion.
9481 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009482
Douglas Gregor29c42f22012-02-24 07:38:34 +00009483 TypeLocBuilder TLB;
9484 TLB.reserve(From->getTypeLoc().getFullDataSize());
9485
9486 QualType To = getDerived().TransformType(TLB, PatternTL);
9487 if (To.isNull())
9488 return ExprError();
9489
Chad Rosier1dcde962012-08-08 18:46:20 +00009490 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009491 PatternTL.getSourceRange(),
9492 ExpansionTL.getEllipsisLoc(),
9493 NumExpansions);
9494 if (To.isNull())
9495 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009496
Douglas Gregor29c42f22012-02-24 07:38:34 +00009497 PackExpansionTypeLoc ToExpansionTL
9498 = TLB.push<PackExpansionTypeLoc>(To);
9499 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9500 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9501 continue;
9502 }
9503
9504 // Expand the pack expansion by substituting for each argument in the
9505 // pack(s).
9506 for (unsigned I = 0; I != *NumExpansions; ++I) {
9507 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9508 TypeLocBuilder TLB;
9509 TLB.reserve(PatternTL.getFullDataSize());
9510 QualType To = getDerived().TransformType(TLB, PatternTL);
9511 if (To.isNull())
9512 return ExprError();
9513
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009514 if (To->containsUnexpandedParameterPack()) {
9515 To = getDerived().RebuildPackExpansionType(To,
9516 PatternTL.getSourceRange(),
9517 ExpansionTL.getEllipsisLoc(),
9518 NumExpansions);
9519 if (To.isNull())
9520 return ExprError();
9521
9522 PackExpansionTypeLoc ToExpansionTL
9523 = TLB.push<PackExpansionTypeLoc>(To);
9524 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9525 }
9526
Douglas Gregor29c42f22012-02-24 07:38:34 +00009527 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9528 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009529
Douglas Gregor29c42f22012-02-24 07:38:34 +00009530 if (!RetainExpansion)
9531 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009532
Douglas Gregor29c42f22012-02-24 07:38:34 +00009533 // If we're supposed to retain a pack expansion, do so by temporarily
9534 // forgetting the partially-substituted parameter pack.
9535 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9536
9537 TypeLocBuilder TLB;
9538 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009539
Douglas Gregor29c42f22012-02-24 07:38:34 +00009540 QualType To = getDerived().TransformType(TLB, PatternTL);
9541 if (To.isNull())
9542 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009543
9544 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009545 PatternTL.getSourceRange(),
9546 ExpansionTL.getEllipsisLoc(),
9547 NumExpansions);
9548 if (To.isNull())
9549 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009550
Douglas Gregor29c42f22012-02-24 07:38:34 +00009551 PackExpansionTypeLoc ToExpansionTL
9552 = TLB.push<PackExpansionTypeLoc>(To);
9553 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9554 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009556
Douglas Gregor29c42f22012-02-24 07:38:34 +00009557 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009558 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009559
9560 return getDerived().RebuildTypeTrait(E->getTrait(),
9561 E->getLocStart(),
9562 Args,
9563 E->getLocEnd());
9564}
9565
9566template<typename Derived>
9567ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009568TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9569 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9570 if (!T)
9571 return ExprError();
9572
9573 if (!getDerived().AlwaysRebuild() &&
9574 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009575 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009576
9577 ExprResult SubExpr;
9578 {
9579 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9580 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9581 if (SubExpr.isInvalid())
9582 return ExprError();
9583
9584 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009585 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009586 }
9587
9588 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9589 E->getLocStart(),
9590 T,
9591 SubExpr.get(),
9592 E->getLocEnd());
9593}
9594
9595template<typename Derived>
9596ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009597TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9598 ExprResult SubExpr;
9599 {
9600 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9601 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9602 if (SubExpr.isInvalid())
9603 return ExprError();
9604
9605 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009606 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009607 }
9608
9609 return getDerived().RebuildExpressionTrait(
9610 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9611}
9612
Reid Kleckner32506ed2014-06-12 23:03:48 +00009613template <typename Derived>
9614ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9615 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9616 TypeSourceInfo **RecoveryTSI) {
9617 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9618 DRE, AddrTaken, RecoveryTSI);
9619
9620 // Propagate both errors and recovered types, which return ExprEmpty.
9621 if (!NewDRE.isUsable())
9622 return NewDRE;
9623
9624 // We got an expr, wrap it up in parens.
9625 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9626 return PE;
9627 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9628 PE->getRParen());
9629}
9630
9631template <typename Derived>
9632ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9633 DependentScopeDeclRefExpr *E) {
9634 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9635 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009636}
9637
9638template<typename Derived>
9639ExprResult
9640TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9641 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009642 bool IsAddressOfOperand,
9643 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009644 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009645 NestedNameSpecifierLoc QualifierLoc
9646 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9647 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009648 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009649 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009650
John McCall31f82722010-11-12 08:19:04 +00009651 // TODO: If this is a conversion-function-id, verify that the
9652 // destination type name (if present) resolves the same way after
9653 // instantiation as it did in the local scope.
9654
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009655 DeclarationNameInfo NameInfo
9656 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9657 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009659
John McCalle66edc12009-11-24 19:00:30 +00009660 if (!E->hasExplicitTemplateArgs()) {
9661 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009662 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009663 // Note: it is sufficient to compare the Name component of NameInfo:
9664 // if name has not changed, DNLoc has not changed either.
9665 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009666 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009667
Reid Kleckner32506ed2014-06-12 23:03:48 +00009668 return getDerived().RebuildDependentScopeDeclRefExpr(
9669 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9670 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009671 }
John McCall6b51f282009-11-23 01:53:49 +00009672
9673 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009674 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9675 E->getNumTemplateArgs(),
9676 TransArgs))
9677 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009678
Reid Kleckner32506ed2014-06-12 23:03:48 +00009679 return getDerived().RebuildDependentScopeDeclRefExpr(
9680 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9681 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009682}
9683
9684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009685ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009686TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009687 // CXXConstructExprs other than for list-initialization and
9688 // CXXTemporaryObjectExpr are always implicit, so when we have
9689 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009690 if ((E->getNumArgs() == 1 ||
9691 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009692 (!getDerived().DropCallArgument(E->getArg(0))) &&
9693 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009694 return getDerived().TransformExpr(E->getArg(0));
9695
Douglas Gregora16548e2009-08-11 05:31:07 +00009696 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9697
9698 QualType T = getDerived().TransformType(E->getType());
9699 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009700 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009701
9702 CXXConstructorDecl *Constructor
9703 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009704 getDerived().TransformDecl(E->getLocStart(),
9705 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009708
Douglas Gregora16548e2009-08-11 05:31:07 +00009709 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009710 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009711 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009712 &ArgumentChanged))
9713 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009714
Douglas Gregora16548e2009-08-11 05:31:07 +00009715 if (!getDerived().AlwaysRebuild() &&
9716 T == E->getType() &&
9717 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009718 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009719 // Mark the constructor as referenced.
9720 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009721 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009722 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009723 }
Mike Stump11289f42009-09-09 15:08:12 +00009724
Douglas Gregordb121ba2009-12-14 16:27:04 +00009725 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9726 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009727 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009728 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009729 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009730 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009731 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009732 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009733 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009734}
Mike Stump11289f42009-09-09 15:08:12 +00009735
Douglas Gregora16548e2009-08-11 05:31:07 +00009736/// \brief Transform a C++ temporary-binding expression.
9737///
Douglas Gregor363b1512009-12-24 18:51:59 +00009738/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9739/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009742TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009743 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009744}
Mike Stump11289f42009-09-09 15:08:12 +00009745
John McCall5d413782010-12-06 08:20:24 +00009746/// \brief Transform a C++ expression that contains cleanups that should
9747/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009748///
John McCall5d413782010-12-06 08:20:24 +00009749/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009750/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009752ExprResult
John McCall5d413782010-12-06 08:20:24 +00009753TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009754 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009755}
Mike Stump11289f42009-09-09 15:08:12 +00009756
Douglas Gregora16548e2009-08-11 05:31:07 +00009757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009758ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009759TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009760 CXXTemporaryObjectExpr *E) {
9761 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9762 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009764
Douglas Gregora16548e2009-08-11 05:31:07 +00009765 CXXConstructorDecl *Constructor
9766 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009767 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009768 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009769 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009771
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009773 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009774 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009775 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009776 &ArgumentChanged))
9777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009780 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009782 !ArgumentChanged) {
9783 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009784 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009785 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009786 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009787
Richard Smithd59b8322012-12-19 01:39:02 +00009788 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009789 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9790 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009791 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009792 E->getLocEnd());
9793}
Mike Stump11289f42009-09-09 15:08:12 +00009794
Douglas Gregora16548e2009-08-11 05:31:07 +00009795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009796ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009797TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009798 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009799 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009800 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009801 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9802 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009803 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009804 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009805 CEnd = E->capture_end();
9806 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009807 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009808 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009809 EnterExpressionEvaluationContext EEEC(getSema(),
9810 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009811 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9812 C->getCapturedVar()->getInit(),
9813 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009814
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009815 if (NewExprInitResult.isInvalid())
9816 return ExprError();
9817 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009818
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009819 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009820 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009821 getSema().buildLambdaInitCaptureInitialization(
9822 C->getLocation(), OldVD->getType()->isReferenceType(),
9823 OldVD->getIdentifier(),
9824 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009825 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009826 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9827 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009828 }
9829
Faisal Vali2cba1332013-10-23 06:44:28 +00009830 // Transform the template parameters, and add them to the current
9831 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009832 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009833 E->getTemplateParameterList());
9834
Richard Smith01014ce2014-11-20 23:53:14 +00009835 // Transform the type of the original lambda's call operator.
9836 // The transformation MUST be done in the CurrentInstantiationScope since
9837 // it introduces a mapping of the original to the newly created
9838 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009839 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009840 {
9841 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9842 FunctionProtoTypeLoc OldCallOpFPTL =
9843 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009844
9845 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009846 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009847 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009848 QualType NewCallOpType = TransformFunctionProtoType(
9849 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009850 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9851 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9852 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009853 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009854 if (NewCallOpType.isNull())
9855 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009856 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9857 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009858 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009859
Richard Smithc38498f2015-04-27 21:27:54 +00009860 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9861 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9862 LSI->GLTemplateParameterList = TPL;
9863
Eli Friedmand564afb2012-09-19 01:18:11 +00009864 // Create the local class that will describe the lambda.
9865 CXXRecordDecl *Class
9866 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009867 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009868 /*KnownDependent=*/false,
9869 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009870 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9871
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009872 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009873 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9874 Class, E->getIntroducerRange(), NewCallOpTSI,
9875 E->getCallOperator()->getLocEnd(),
9876 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009877 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009878
Faisal Vali2cba1332013-10-23 06:44:28 +00009879 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009880 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009881
Douglas Gregorb4328232012-02-14 00:00:48 +00009882 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009883 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009884 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009885
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009886 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009887 getSema().buildLambdaScope(LSI, NewCallOperator,
9888 E->getIntroducerRange(),
9889 E->getCaptureDefault(),
9890 E->getCaptureDefaultLoc(),
9891 E->hasExplicitParameters(),
9892 E->hasExplicitResultType(),
9893 E->isMutable());
9894
9895 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009896
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009897 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009898 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009899 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009900 CEnd = E->capture_end();
9901 C != CEnd; ++C) {
9902 // When we hit the first implicit capture, tell Sema that we've finished
9903 // the list of explicit captures.
9904 if (!FinishedExplicitCaptures && C->isImplicit()) {
9905 getSema().finishLambdaExplicitCaptures(LSI);
9906 FinishedExplicitCaptures = true;
9907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009908
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009909 // Capturing 'this' is trivial.
9910 if (C->capturesThis()) {
9911 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9912 continue;
9913 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009914 // Captured expression will be recaptured during captured variables
9915 // rebuilding.
9916 if (C->capturesVLAType())
9917 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009918
Richard Smithba71c082013-05-16 06:20:58 +00009919 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009920 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009921 InitCaptureInfoTy InitExprTypePair =
9922 InitCaptureExprsAndTypes[C - E->capture_begin()];
9923 ExprResult Init = InitExprTypePair.first;
9924 QualType InitQualType = InitExprTypePair.second;
9925 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009926 Invalid = true;
9927 continue;
9928 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009929 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009930 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +00009931 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9932 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009933 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009934 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009935 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009936 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009937 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009938 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009939 continue;
9940 }
9941
9942 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9943
Douglas Gregor3e308b12012-02-14 19:27:52 +00009944 // Determine the capture kind for Sema.
9945 Sema::TryCaptureKind Kind
9946 = C->isImplicit()? Sema::TryCapture_Implicit
9947 : C->getCaptureKind() == LCK_ByCopy
9948 ? Sema::TryCapture_ExplicitByVal
9949 : Sema::TryCapture_ExplicitByRef;
9950 SourceLocation EllipsisLoc;
9951 if (C->isPackExpansion()) {
9952 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9953 bool ShouldExpand = false;
9954 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009955 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009956 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9957 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009958 Unexpanded,
9959 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009960 NumExpansions)) {
9961 Invalid = true;
9962 continue;
9963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009964
Douglas Gregor3e308b12012-02-14 19:27:52 +00009965 if (ShouldExpand) {
9966 // The transform has determined that we should perform an expansion;
9967 // transform and capture each of the arguments.
9968 // expansion of the pattern. Do so.
9969 VarDecl *Pack = C->getCapturedVar();
9970 for (unsigned I = 0; I != *NumExpansions; ++I) {
9971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9972 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009973 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009974 Pack));
9975 if (!CapturedVar) {
9976 Invalid = true;
9977 continue;
9978 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009979
Douglas Gregor3e308b12012-02-14 19:27:52 +00009980 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009981 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9982 }
Richard Smith9467be42014-06-06 17:33:35 +00009983
9984 // FIXME: Retain a pack expansion if RetainExpansion is true.
9985
Douglas Gregor3e308b12012-02-14 19:27:52 +00009986 continue;
9987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009988
Douglas Gregor3e308b12012-02-14 19:27:52 +00009989 EllipsisLoc = C->getEllipsisLoc();
9990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009991
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009992 // Transform the captured variable.
9993 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009994 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009995 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009996 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009997 Invalid = true;
9998 continue;
9999 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010000
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010001 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010002 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10003 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010004 }
10005 if (!FinishedExplicitCaptures)
10006 getSema().finishLambdaExplicitCaptures(LSI);
10007
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010008 // Enter a new evaluation context to insulate the lambda from any
10009 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010010 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010011
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010012 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010013 StmtResult Body =
10014 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10015
10016 // ActOnLambda* will pop the function scope for us.
10017 FuncScopeCleanup.disable();
10018
Douglas Gregorb4328232012-02-14 00:00:48 +000010019 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010020 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010021 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010022 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010023 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010024 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010025
Richard Smithc38498f2015-04-27 21:27:54 +000010026 // Copy the LSI before ActOnFinishFunctionBody removes it.
10027 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10028 // the call operator.
10029 auto LSICopy = *LSI;
10030 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10031 /*IsInstantiation*/ true);
10032 SavedContext.pop();
10033
10034 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10035 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010036}
10037
10038template<typename Derived>
10039ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010040TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010041 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010042 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10043 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010045
Douglas Gregora16548e2009-08-11 05:31:07 +000010046 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010047 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010048 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010049 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010050 &ArgumentChanged))
10051 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010052
Douglas Gregora16548e2009-08-11 05:31:07 +000010053 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010054 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010055 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010056 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010057
Douglas Gregora16548e2009-08-11 05:31:07 +000010058 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010059 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010060 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010061 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010062 E->getRParenLoc());
10063}
Mike Stump11289f42009-09-09 15:08:12 +000010064
Douglas Gregora16548e2009-08-11 05:31:07 +000010065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010066ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010067TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010068 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010069 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010070 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010071 Expr *OldBase;
10072 QualType BaseType;
10073 QualType ObjectType;
10074 if (!E->isImplicitAccess()) {
10075 OldBase = E->getBase();
10076 Base = getDerived().TransformExpr(OldBase);
10077 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010079
John McCall2d74de92009-12-01 22:10:20 +000010080 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010081 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010082 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010083 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010084 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010085 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010086 ObjectTy,
10087 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010088 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010089 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010090
John McCallba7bf592010-08-24 05:47:05 +000010091 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010092 BaseType = ((Expr*) Base.get())->getType();
10093 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010094 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010095 BaseType = getDerived().TransformType(E->getBaseType());
10096 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10097 }
Mike Stump11289f42009-09-09 15:08:12 +000010098
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010099 // Transform the first part of the nested-name-specifier that qualifies
10100 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010101 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010102 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010103 E->getFirstQualifierFoundInScope(),
10104 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010105
Douglas Gregore16af532011-02-28 18:50:33 +000010106 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010107 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010108 QualifierLoc
10109 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10110 ObjectType,
10111 FirstQualifierInScope);
10112 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010114 }
Mike Stump11289f42009-09-09 15:08:12 +000010115
Abramo Bagnara7945c982012-01-27 09:46:47 +000010116 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10117
John McCall31f82722010-11-12 08:19:04 +000010118 // TODO: If this is a conversion-function-id, verify that the
10119 // destination type name (if present) resolves the same way after
10120 // instantiation as it did in the local scope.
10121
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010122 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010123 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010124 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010126
John McCall2d74de92009-12-01 22:10:20 +000010127 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010128 // This is a reference to a member without an explicitly-specified
10129 // template argument list. Optimize for this common case.
10130 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010131 Base.get() == OldBase &&
10132 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010133 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010134 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010135 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010136 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010137
John McCallb268a282010-08-23 23:25:46 +000010138 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010139 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010140 E->isArrow(),
10141 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010142 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010143 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010144 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010145 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010146 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010147 }
10148
John McCall6b51f282009-11-23 01:53:49 +000010149 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010150 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10151 E->getNumTemplateArgs(),
10152 TransArgs))
10153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010154
John McCallb268a282010-08-23 23:25:46 +000010155 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010156 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010157 E->isArrow(),
10158 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010159 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010160 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010161 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010162 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010163 &TransArgs);
10164}
10165
10166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010168TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010169 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010170 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010171 QualType BaseType;
10172 if (!Old->isImplicitAccess()) {
10173 Base = getDerived().TransformExpr(Old->getBase());
10174 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010175 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010176 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010177 Old->isArrow());
10178 if (Base.isInvalid())
10179 return ExprError();
10180 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010181 } else {
10182 BaseType = getDerived().TransformType(Old->getBaseType());
10183 }
John McCall10eae182009-11-30 22:42:35 +000010184
Douglas Gregor0da1d432011-02-28 20:01:57 +000010185 NestedNameSpecifierLoc QualifierLoc;
10186 if (Old->getQualifierLoc()) {
10187 QualifierLoc
10188 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10189 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010190 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010191 }
10192
Abramo Bagnara7945c982012-01-27 09:46:47 +000010193 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10194
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010195 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010196 Sema::LookupOrdinaryName);
10197
10198 // Transform all the decls.
10199 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10200 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010201 NamedDecl *InstD = static_cast<NamedDecl*>(
10202 getDerived().TransformDecl(Old->getMemberLoc(),
10203 *I));
John McCall84d87672009-12-10 09:41:52 +000010204 if (!InstD) {
10205 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10206 // This can happen because of dependent hiding.
10207 if (isa<UsingShadowDecl>(*I))
10208 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010209 else {
10210 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010211 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010212 }
John McCall84d87672009-12-10 09:41:52 +000010213 }
John McCall10eae182009-11-30 22:42:35 +000010214
10215 // Expand using declarations.
10216 if (isa<UsingDecl>(InstD)) {
10217 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010218 for (auto *I : UD->shadows())
10219 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010220 continue;
10221 }
10222
10223 R.addDecl(InstD);
10224 }
10225
10226 R.resolveKind();
10227
Douglas Gregor9262f472010-04-27 18:19:34 +000010228 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010229 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010230 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010231 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010232 Old->getMemberLoc(),
10233 Old->getNamingClass()));
10234 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010235 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010236
Douglas Gregorda7be082010-04-27 16:10:10 +000010237 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010238 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010239
John McCall10eae182009-11-30 22:42:35 +000010240 TemplateArgumentListInfo TransArgs;
10241 if (Old->hasExplicitTemplateArgs()) {
10242 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10243 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010244 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10245 Old->getNumTemplateArgs(),
10246 TransArgs))
10247 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010248 }
John McCall38836f02010-01-15 08:34:02 +000010249
10250 // FIXME: to do this check properly, we will need to preserve the
10251 // first-qualifier-in-scope here, just in case we had a dependent
10252 // base (and therefore couldn't do the check) and a
10253 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010254 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010255
John McCallb268a282010-08-23 23:25:46 +000010256 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010257 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010258 Old->getOperatorLoc(),
10259 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010260 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010261 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010262 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010263 R,
10264 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010265 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010266}
10267
10268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010269ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010270TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010271 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010272 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10273 if (SubExpr.isInvalid())
10274 return ExprError();
10275
10276 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010277 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010278
10279 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10280}
10281
10282template<typename Derived>
10283ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010284TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010285 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10286 if (Pattern.isInvalid())
10287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010288
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010289 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010290 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010291
Douglas Gregorb8840002011-01-14 21:20:45 +000010292 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10293 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010294}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010295
10296template<typename Derived>
10297ExprResult
10298TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10299 // If E is not value-dependent, then nothing will change when we transform it.
10300 // Note: This is an instantiation-centric view.
10301 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010302 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010303
Richard Smithd784e682015-09-23 21:41:42 +000010304 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010305
Richard Smithd784e682015-09-23 21:41:42 +000010306 ArrayRef<TemplateArgument> PackArgs;
10307 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010308
Richard Smithd784e682015-09-23 21:41:42 +000010309 // Find the argument list to transform.
10310 if (E->isPartiallySubstituted()) {
10311 PackArgs = E->getPartialArguments();
10312 } else if (E->isValueDependent()) {
10313 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10314 bool ShouldExpand = false;
10315 bool RetainExpansion = false;
10316 Optional<unsigned> NumExpansions;
10317 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10318 Unexpanded,
10319 ShouldExpand, RetainExpansion,
10320 NumExpansions))
10321 return ExprError();
10322
10323 // If we need to expand the pack, build a template argument from it and
10324 // expand that.
10325 if (ShouldExpand) {
10326 auto *Pack = E->getPack();
10327 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10328 ArgStorage = getSema().Context.getPackExpansionType(
10329 getSema().Context.getTypeDeclType(TTPD), None);
10330 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10331 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10332 } else {
10333 auto *VD = cast<ValueDecl>(Pack);
10334 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10335 VK_RValue, E->getPackLoc());
10336 if (DRE.isInvalid())
10337 return ExprError();
10338 ArgStorage = new (getSema().Context) PackExpansionExpr(
10339 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10340 }
10341 PackArgs = ArgStorage;
10342 }
10343 }
10344
10345 // If we're not expanding the pack, just transform the decl.
10346 if (!PackArgs.size()) {
10347 auto *Pack = cast_or_null<NamedDecl>(
10348 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010349 if (!Pack)
10350 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010351 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10352 E->getPackLoc(),
10353 E->getRParenLoc(), None, None);
10354 }
10355
10356 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10357 E->getPackLoc());
10358 {
10359 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10360 typedef TemplateArgumentLocInventIterator<
10361 Derived, const TemplateArgument*> PackLocIterator;
10362 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10363 PackLocIterator(*this, PackArgs.end()),
10364 TransformedPackArgs, /*Uneval*/true))
10365 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010366 }
10367
Richard Smithd784e682015-09-23 21:41:42 +000010368 SmallVector<TemplateArgument, 8> Args;
10369 bool PartialSubstitution = false;
10370 for (auto &Loc : TransformedPackArgs.arguments()) {
10371 Args.push_back(Loc.getArgument());
10372 if (Loc.getArgument().isPackExpansion())
10373 PartialSubstitution = true;
10374 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010375
Richard Smithd784e682015-09-23 21:41:42 +000010376 if (PartialSubstitution)
10377 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10378 E->getPackLoc(),
10379 E->getRParenLoc(), None, Args);
10380
10381 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010382 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010383 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010384}
10385
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010386template<typename Derived>
10387ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010388TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10389 SubstNonTypeTemplateParmPackExpr *E) {
10390 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010391 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010392}
10393
10394template<typename Derived>
10395ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010396TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10397 SubstNonTypeTemplateParmExpr *E) {
10398 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010399 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010400}
10401
10402template<typename Derived>
10403ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010404TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10405 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010406 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010407}
10408
10409template<typename Derived>
10410ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010411TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10412 MaterializeTemporaryExpr *E) {
10413 return getDerived().TransformExpr(E->GetTemporaryExpr());
10414}
Chad Rosier1dcde962012-08-08 18:46:20 +000010415
Douglas Gregorfe314812011-06-21 17:03:29 +000010416template<typename Derived>
10417ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010418TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10419 Expr *Pattern = E->getPattern();
10420
10421 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10422 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10423 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10424
10425 // Determine whether the set of unexpanded parameter packs can and should
10426 // be expanded.
10427 bool Expand = true;
10428 bool RetainExpansion = false;
10429 Optional<unsigned> NumExpansions;
10430 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10431 Pattern->getSourceRange(),
10432 Unexpanded,
10433 Expand, RetainExpansion,
10434 NumExpansions))
10435 return true;
10436
10437 if (!Expand) {
10438 // Do not expand any packs here, just transform and rebuild a fold
10439 // expression.
10440 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10441
10442 ExprResult LHS =
10443 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10444 if (LHS.isInvalid())
10445 return true;
10446
10447 ExprResult RHS =
10448 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10449 if (RHS.isInvalid())
10450 return true;
10451
10452 if (!getDerived().AlwaysRebuild() &&
10453 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10454 return E;
10455
10456 return getDerived().RebuildCXXFoldExpr(
10457 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10458 RHS.get(), E->getLocEnd());
10459 }
10460
10461 // The transform has determined that we should perform an elementwise
10462 // expansion of the pattern. Do so.
10463 ExprResult Result = getDerived().TransformExpr(E->getInit());
10464 if (Result.isInvalid())
10465 return true;
10466 bool LeftFold = E->isLeftFold();
10467
10468 // If we're retaining an expansion for a right fold, it is the innermost
10469 // component and takes the init (if any).
10470 if (!LeftFold && RetainExpansion) {
10471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10472
10473 ExprResult Out = getDerived().TransformExpr(Pattern);
10474 if (Out.isInvalid())
10475 return true;
10476
10477 Result = getDerived().RebuildCXXFoldExpr(
10478 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10479 Result.get(), E->getLocEnd());
10480 if (Result.isInvalid())
10481 return true;
10482 }
10483
10484 for (unsigned I = 0; I != *NumExpansions; ++I) {
10485 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10486 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10487 ExprResult Out = getDerived().TransformExpr(Pattern);
10488 if (Out.isInvalid())
10489 return true;
10490
10491 if (Out.get()->containsUnexpandedParameterPack()) {
10492 // We still have a pack; retain a pack expansion for this slice.
10493 Result = getDerived().RebuildCXXFoldExpr(
10494 E->getLocStart(),
10495 LeftFold ? Result.get() : Out.get(),
10496 E->getOperator(), E->getEllipsisLoc(),
10497 LeftFold ? Out.get() : Result.get(),
10498 E->getLocEnd());
10499 } else if (Result.isUsable()) {
10500 // We've got down to a single element; build a binary operator.
10501 Result = getDerived().RebuildBinaryOperator(
10502 E->getEllipsisLoc(), E->getOperator(),
10503 LeftFold ? Result.get() : Out.get(),
10504 LeftFold ? Out.get() : Result.get());
10505 } else
10506 Result = Out;
10507
10508 if (Result.isInvalid())
10509 return true;
10510 }
10511
10512 // If we're retaining an expansion for a left fold, it is the outermost
10513 // component and takes the complete expansion so far as its init (if any).
10514 if (LeftFold && RetainExpansion) {
10515 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10516
10517 ExprResult Out = getDerived().TransformExpr(Pattern);
10518 if (Out.isInvalid())
10519 return true;
10520
10521 Result = getDerived().RebuildCXXFoldExpr(
10522 E->getLocStart(), Result.get(),
10523 E->getOperator(), E->getEllipsisLoc(),
10524 Out.get(), E->getLocEnd());
10525 if (Result.isInvalid())
10526 return true;
10527 }
10528
10529 // If we had no init and an empty pack, and we're not retaining an expansion,
10530 // then produce a fallback value or error.
10531 if (Result.isUnset())
10532 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10533 E->getOperator());
10534
10535 return Result;
10536}
10537
10538template<typename Derived>
10539ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010540TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10541 CXXStdInitializerListExpr *E) {
10542 return getDerived().TransformExpr(E->getSubExpr());
10543}
10544
10545template<typename Derived>
10546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010547TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010548 return SemaRef.MaybeBindToTemporary(E);
10549}
10550
10551template<typename Derived>
10552ExprResult
10553TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010554 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010555}
10556
10557template<typename Derived>
10558ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010559TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10560 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10561 if (SubExpr.isInvalid())
10562 return ExprError();
10563
10564 if (!getDerived().AlwaysRebuild() &&
10565 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010566 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010567
10568 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010569}
10570
10571template<typename Derived>
10572ExprResult
10573TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10574 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010575 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010576 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010577 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010578 /*IsCall=*/false, Elements, &ArgChanged))
10579 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010580
Ted Kremeneke65b0862012-03-06 20:05:56 +000010581 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10582 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010583
Ted Kremeneke65b0862012-03-06 20:05:56 +000010584 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10585 Elements.data(),
10586 Elements.size());
10587}
10588
10589template<typename Derived>
10590ExprResult
10591TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010592 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010593 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010594 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010595 bool ArgChanged = false;
10596 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10597 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010598
Ted Kremeneke65b0862012-03-06 20:05:56 +000010599 if (OrigElement.isPackExpansion()) {
10600 // This key/value element is a pack expansion.
10601 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10602 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10603 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10604 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10605
10606 // Determine whether the set of unexpanded parameter packs can
10607 // and should be expanded.
10608 bool Expand = true;
10609 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010610 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10611 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010612 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10613 OrigElement.Value->getLocEnd());
10614 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10615 PatternRange,
10616 Unexpanded,
10617 Expand, RetainExpansion,
10618 NumExpansions))
10619 return ExprError();
10620
10621 if (!Expand) {
10622 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010623 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010624 // expansion.
10625 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10626 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10627 if (Key.isInvalid())
10628 return ExprError();
10629
10630 if (Key.get() != OrigElement.Key)
10631 ArgChanged = true;
10632
10633 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10634 if (Value.isInvalid())
10635 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010636
Ted Kremeneke65b0862012-03-06 20:05:56 +000010637 if (Value.get() != OrigElement.Value)
10638 ArgChanged = true;
10639
Chad Rosier1dcde962012-08-08 18:46:20 +000010640 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010641 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10642 };
10643 Elements.push_back(Expansion);
10644 continue;
10645 }
10646
10647 // Record right away that the argument was changed. This needs
10648 // to happen even if the array expands to nothing.
10649 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010650
Ted Kremeneke65b0862012-03-06 20:05:56 +000010651 // The transform has determined that we should perform an elementwise
10652 // expansion of the pattern. Do so.
10653 for (unsigned I = 0; I != *NumExpansions; ++I) {
10654 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10655 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10656 if (Key.isInvalid())
10657 return ExprError();
10658
10659 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10660 if (Value.isInvalid())
10661 return ExprError();
10662
Chad Rosier1dcde962012-08-08 18:46:20 +000010663 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010664 Key.get(), Value.get(), SourceLocation(), NumExpansions
10665 };
10666
10667 // If any unexpanded parameter packs remain, we still have a
10668 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010669 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010670 if (Key.get()->containsUnexpandedParameterPack() ||
10671 Value.get()->containsUnexpandedParameterPack())
10672 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010673
Ted Kremeneke65b0862012-03-06 20:05:56 +000010674 Elements.push_back(Element);
10675 }
10676
Richard Smith9467be42014-06-06 17:33:35 +000010677 // FIXME: Retain a pack expansion if RetainExpansion is true.
10678
Ted Kremeneke65b0862012-03-06 20:05:56 +000010679 // We've finished with this pack expansion.
10680 continue;
10681 }
10682
10683 // Transform and check key.
10684 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10685 if (Key.isInvalid())
10686 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010687
Ted Kremeneke65b0862012-03-06 20:05:56 +000010688 if (Key.get() != OrigElement.Key)
10689 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010690
Ted Kremeneke65b0862012-03-06 20:05:56 +000010691 // Transform and check value.
10692 ExprResult Value
10693 = getDerived().TransformExpr(OrigElement.Value);
10694 if (Value.isInvalid())
10695 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010696
Ted Kremeneke65b0862012-03-06 20:05:56 +000010697 if (Value.get() != OrigElement.Value)
10698 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010699
10700 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010701 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010702 };
10703 Elements.push_back(Element);
10704 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010705
Ted Kremeneke65b0862012-03-06 20:05:56 +000010706 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10707 return SemaRef.MaybeBindToTemporary(E);
10708
10709 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10710 Elements.data(),
10711 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010712}
10713
Mike Stump11289f42009-09-09 15:08:12 +000010714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010716TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010717 TypeSourceInfo *EncodedTypeInfo
10718 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10719 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010721
Douglas Gregora16548e2009-08-11 05:31:07 +000010722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010723 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010724 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010725
10726 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010727 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010728 E->getRParenLoc());
10729}
Mike Stump11289f42009-09-09 15:08:12 +000010730
Douglas Gregora16548e2009-08-11 05:31:07 +000010731template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010732ExprResult TreeTransform<Derived>::
10733TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010734 // This is a kind of implicit conversion, and it needs to get dropped
10735 // and recomputed for the same general reasons that ImplicitCastExprs
10736 // do, as well a more specific one: this expression is only valid when
10737 // it appears *immediately* as an argument expression.
10738 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010739}
10740
10741template<typename Derived>
10742ExprResult TreeTransform<Derived>::
10743TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010744 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010745 = getDerived().TransformType(E->getTypeInfoAsWritten());
10746 if (!TSInfo)
10747 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010748
John McCall31168b02011-06-15 23:02:42 +000010749 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010750 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010751 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010752
John McCall31168b02011-06-15 23:02:42 +000010753 if (!getDerived().AlwaysRebuild() &&
10754 TSInfo == E->getTypeInfoAsWritten() &&
10755 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010756 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010757
John McCall31168b02011-06-15 23:02:42 +000010758 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010759 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010760 Result.get());
10761}
10762
10763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010765TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010766 // Transform arguments.
10767 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010768 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010769 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010770 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010771 &ArgChanged))
10772 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010773
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010774 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10775 // Class message: transform the receiver type.
10776 TypeSourceInfo *ReceiverTypeInfo
10777 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10778 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010779 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010780
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010781 // If nothing changed, just retain the existing message send.
10782 if (!getDerived().AlwaysRebuild() &&
10783 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010784 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010785
10786 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010787 SmallVector<SourceLocation, 16> SelLocs;
10788 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010789 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10790 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010791 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010792 E->getMethodDecl(),
10793 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010794 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010795 E->getRightLoc());
10796 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010797 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10798 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10799 // Build a new class message send to 'super'.
10800 SmallVector<SourceLocation, 16> SelLocs;
10801 E->getSelectorLocs(SelLocs);
10802 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10803 E->getSelector(),
10804 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010805 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010806 E->getMethodDecl(),
10807 E->getLeftLoc(),
10808 Args,
10809 E->getRightLoc());
10810 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010811
10812 // Instance message: transform the receiver
10813 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10814 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010815 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010816 = getDerived().TransformExpr(E->getInstanceReceiver());
10817 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010818 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010819
10820 // If nothing changed, just retain the existing message send.
10821 if (!getDerived().AlwaysRebuild() &&
10822 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010823 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010824
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010825 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010826 SmallVector<SourceLocation, 16> SelLocs;
10827 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010828 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010829 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010830 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010831 E->getMethodDecl(),
10832 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010833 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010834 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010835}
10836
Mike Stump11289f42009-09-09 15:08:12 +000010837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010838ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010839TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010840 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010841}
10842
Mike Stump11289f42009-09-09 15:08:12 +000010843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010845TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010846 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010847}
10848
Mike Stump11289f42009-09-09 15:08:12 +000010849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010851TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010852 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010853 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010854 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010855 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010856
10857 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010858
Douglas Gregord51d90d2010-04-26 20:11:03 +000010859 // If nothing changed, just retain the existing expression.
10860 if (!getDerived().AlwaysRebuild() &&
10861 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010862 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010863
John McCallb268a282010-08-23 23:25:46 +000010864 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010865 E->getLocation(),
10866 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010867}
10868
Mike Stump11289f42009-09-09 15:08:12 +000010869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010871TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010872 // 'super' and types never change. Property never changes. Just
10873 // retain the existing expression.
10874 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010875 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010876
Douglas Gregor9faee212010-04-26 20:47:02 +000010877 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010878 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010879 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010880 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010881
Douglas Gregor9faee212010-04-26 20:47:02 +000010882 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010883
Douglas Gregor9faee212010-04-26 20:47:02 +000010884 // If nothing changed, just retain the existing expression.
10885 if (!getDerived().AlwaysRebuild() &&
10886 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010887 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010888
John McCallb7bd14f2010-12-02 01:19:52 +000010889 if (E->isExplicitProperty())
10890 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10891 E->getExplicitProperty(),
10892 E->getLocation());
10893
10894 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010895 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010896 E->getImplicitPropertyGetter(),
10897 E->getImplicitPropertySetter(),
10898 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010899}
10900
Mike Stump11289f42009-09-09 15:08:12 +000010901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010902ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010903TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10904 // Transform the base expression.
10905 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10906 if (Base.isInvalid())
10907 return ExprError();
10908
10909 // Transform the key expression.
10910 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10911 if (Key.isInvalid())
10912 return ExprError();
10913
10914 // If nothing changed, just retain the existing expression.
10915 if (!getDerived().AlwaysRebuild() &&
10916 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010917 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010918
Chad Rosier1dcde962012-08-08 18:46:20 +000010919 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010920 Base.get(), Key.get(),
10921 E->getAtIndexMethodDecl(),
10922 E->setAtIndexMethodDecl());
10923}
10924
10925template<typename Derived>
10926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010927TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010928 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010929 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010930 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010932
Douglas Gregord51d90d2010-04-26 20:11:03 +000010933 // If nothing changed, just retain the existing expression.
10934 if (!getDerived().AlwaysRebuild() &&
10935 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010936 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010937
John McCallb268a282010-08-23 23:25:46 +000010938 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010939 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010940 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010941}
10942
Mike Stump11289f42009-09-09 15:08:12 +000010943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010945TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010946 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010947 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010948 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010949 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010950 SubExprs, &ArgumentChanged))
10951 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010952
Douglas Gregora16548e2009-08-11 05:31:07 +000010953 if (!getDerived().AlwaysRebuild() &&
10954 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010955 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010956
Douglas Gregora16548e2009-08-11 05:31:07 +000010957 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010958 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010959 E->getRParenLoc());
10960}
10961
Mike Stump11289f42009-09-09 15:08:12 +000010962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010963ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010964TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10965 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10966 if (SrcExpr.isInvalid())
10967 return ExprError();
10968
10969 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10970 if (!Type)
10971 return ExprError();
10972
10973 if (!getDerived().AlwaysRebuild() &&
10974 Type == E->getTypeSourceInfo() &&
10975 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010976 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010977
10978 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10979 SrcExpr.get(), Type,
10980 E->getRParenLoc());
10981}
10982
10983template<typename Derived>
10984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010985TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010986 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010987
Craig Topperc3ec1492014-05-26 06:22:03 +000010988 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010989 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10990
10991 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010992 blockScope->TheDecl->setBlockMissingReturnType(
10993 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010994
Chris Lattner01cf8db2011-07-20 06:58:45 +000010995 SmallVector<ParmVarDecl*, 4> params;
10996 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010997
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010998 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010999 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11000 oldBlock->param_begin(),
11001 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011002 nullptr, paramTypes, &params)) {
11003 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011004 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011005 }
John McCall490112f2011-02-04 18:33:18 +000011006
Jordan Rosea0a86be2013-03-08 22:25:36 +000011007 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000011008 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011009 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011010
Jordan Rose5c382722013-03-08 21:51:21 +000011011 QualType functionType =
11012 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011013 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000011014 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011015
11016 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011017 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011018 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011019
11020 if (!oldBlock->blockMissingReturnType()) {
11021 blockScope->HasImplicitReturnType = false;
11022 blockScope->ReturnType = exprResultType;
11023 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011024
John McCall3882ace2011-01-05 12:14:39 +000011025 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011026 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011027 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011028 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011029 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011030 }
John McCall3882ace2011-01-05 12:14:39 +000011031
John McCall490112f2011-02-04 18:33:18 +000011032#ifndef NDEBUG
11033 // In builds with assertions, make sure that we captured everything we
11034 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011035 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011036 for (const auto &I : oldBlock->captures()) {
11037 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011038
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011039 // Ignore parameter packs.
11040 if (isa<ParmVarDecl>(oldCapture) &&
11041 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11042 continue;
John McCall490112f2011-02-04 18:33:18 +000011043
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011044 VarDecl *newCapture =
11045 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11046 oldCapture));
11047 assert(blockScope->CaptureMap.count(newCapture));
11048 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011049 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011050 }
11051#endif
11052
11053 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011054 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011055}
11056
Mike Stump11289f42009-09-09 15:08:12 +000011057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011058ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011059TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011060 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011061}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011062
11063template<typename Derived>
11064ExprResult
11065TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011066 QualType RetTy = getDerived().TransformType(E->getType());
11067 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011068 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011069 SubExprs.reserve(E->getNumSubExprs());
11070 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11071 SubExprs, &ArgumentChanged))
11072 return ExprError();
11073
11074 if (!getDerived().AlwaysRebuild() &&
11075 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011076 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011077
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011078 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011079 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011080}
Chad Rosier1dcde962012-08-08 18:46:20 +000011081
Douglas Gregora16548e2009-08-11 05:31:07 +000011082//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011083// Type reconstruction
11084//===----------------------------------------------------------------------===//
11085
Mike Stump11289f42009-09-09 15:08:12 +000011086template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011087QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11088 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011089 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011090 getDerived().getBaseEntity());
11091}
11092
Mike Stump11289f42009-09-09 15:08:12 +000011093template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011094QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11095 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011096 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011097 getDerived().getBaseEntity());
11098}
11099
Mike Stump11289f42009-09-09 15:08:12 +000011100template<typename Derived>
11101QualType
John McCall70dd5f62009-10-30 00:06:24 +000011102TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11103 bool WrittenAsLValue,
11104 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011105 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011106 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011107}
11108
11109template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011110QualType
John McCall70dd5f62009-10-30 00:06:24 +000011111TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11112 QualType ClassType,
11113 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011114 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11115 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011116}
11117
11118template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011119QualType TreeTransform<Derived>::RebuildObjCObjectType(
11120 QualType BaseType,
11121 SourceLocation Loc,
11122 SourceLocation TypeArgsLAngleLoc,
11123 ArrayRef<TypeSourceInfo *> TypeArgs,
11124 SourceLocation TypeArgsRAngleLoc,
11125 SourceLocation ProtocolLAngleLoc,
11126 ArrayRef<ObjCProtocolDecl *> Protocols,
11127 ArrayRef<SourceLocation> ProtocolLocs,
11128 SourceLocation ProtocolRAngleLoc) {
11129 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11130 TypeArgs, TypeArgsRAngleLoc,
11131 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11132 ProtocolRAngleLoc,
11133 /*FailOnError=*/true);
11134}
11135
11136template<typename Derived>
11137QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11138 QualType PointeeType,
11139 SourceLocation Star) {
11140 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11141}
11142
11143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011144QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011145TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11146 ArrayType::ArraySizeModifier SizeMod,
11147 const llvm::APInt *Size,
11148 Expr *SizeExpr,
11149 unsigned IndexTypeQuals,
11150 SourceRange BracketsRange) {
11151 if (SizeExpr || !Size)
11152 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11153 IndexTypeQuals, BracketsRange,
11154 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011155
11156 QualType Types[] = {
11157 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11158 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11159 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011160 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011161 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011162 QualType SizeType;
11163 for (unsigned I = 0; I != NumTypes; ++I)
11164 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11165 SizeType = Types[I];
11166 break;
11167 }
Mike Stump11289f42009-09-09 15:08:12 +000011168
Eli Friedman9562f392012-01-25 23:20:27 +000011169 // Note that we can return a VariableArrayType here in the case where
11170 // the element type was a dependent VariableArrayType.
11171 IntegerLiteral *ArraySize
11172 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11173 /*FIXME*/BracketsRange.getBegin());
11174 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011175 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011176 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011177}
Mike Stump11289f42009-09-09 15:08:12 +000011178
Douglas Gregord6ff3322009-08-04 16:50:30 +000011179template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011180QualType
11181TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011182 ArrayType::ArraySizeModifier SizeMod,
11183 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011184 unsigned IndexTypeQuals,
11185 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011186 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011187 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011188}
11189
11190template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011191QualType
Mike Stump11289f42009-09-09 15:08:12 +000011192TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011193 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011194 unsigned IndexTypeQuals,
11195 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011196 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011197 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011198}
Mike Stump11289f42009-09-09 15:08:12 +000011199
Douglas Gregord6ff3322009-08-04 16:50:30 +000011200template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011201QualType
11202TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011203 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011204 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011205 unsigned IndexTypeQuals,
11206 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011207 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011208 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011209 IndexTypeQuals, BracketsRange);
11210}
11211
11212template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011213QualType
11214TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011215 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011216 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011217 unsigned IndexTypeQuals,
11218 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011219 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011220 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011221 IndexTypeQuals, BracketsRange);
11222}
11223
11224template<typename Derived>
11225QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011226 unsigned NumElements,
11227 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011228 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011229 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011230}
Mike Stump11289f42009-09-09 15:08:12 +000011231
Douglas Gregord6ff3322009-08-04 16:50:30 +000011232template<typename Derived>
11233QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11234 unsigned NumElements,
11235 SourceLocation AttributeLoc) {
11236 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11237 NumElements, true);
11238 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011239 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11240 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011241 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011242}
Mike Stump11289f42009-09-09 15:08:12 +000011243
Douglas Gregord6ff3322009-08-04 16:50:30 +000011244template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011245QualType
11246TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011247 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011248 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011249 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011250}
Mike Stump11289f42009-09-09 15:08:12 +000011251
Douglas Gregord6ff3322009-08-04 16:50:30 +000011252template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011253QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11254 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011255 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011256 const FunctionProtoType::ExtProtoInfo &EPI) {
11257 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011258 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011259 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011260 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011261}
Mike Stump11289f42009-09-09 15:08:12 +000011262
Douglas Gregord6ff3322009-08-04 16:50:30 +000011263template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011264QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11265 return SemaRef.Context.getFunctionNoProtoType(T);
11266}
11267
11268template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011269QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11270 assert(D && "no decl found");
11271 if (D->isInvalidDecl()) return QualType();
11272
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011273 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011274 TypeDecl *Ty;
11275 if (isa<UsingDecl>(D)) {
11276 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011277 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011278 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11279
11280 // A valid resolved using typename decl points to exactly one type decl.
11281 assert(++Using->shadow_begin() == Using->shadow_end());
11282 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011283
John McCallb96ec562009-12-04 22:46:56 +000011284 } else {
11285 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11286 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11287 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11288 }
11289
11290 return SemaRef.Context.getTypeDeclType(Ty);
11291}
11292
11293template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011294QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11295 SourceLocation Loc) {
11296 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011297}
11298
11299template<typename Derived>
11300QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11301 return SemaRef.Context.getTypeOfType(Underlying);
11302}
11303
11304template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011305QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11306 SourceLocation Loc) {
11307 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011308}
11309
11310template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011311QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11312 UnaryTransformType::UTTKind UKind,
11313 SourceLocation Loc) {
11314 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11315}
11316
11317template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011318QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011319 TemplateName Template,
11320 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011321 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011322 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011323}
Mike Stump11289f42009-09-09 15:08:12 +000011324
Douglas Gregor1135c352009-08-06 05:28:30 +000011325template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011326QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11327 SourceLocation KWLoc) {
11328 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11329}
11330
11331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011332TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011333TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011334 bool TemplateKW,
11335 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011336 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011337 Template);
11338}
11339
11340template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011341TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011342TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11343 const IdentifierInfo &Name,
11344 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011345 QualType ObjectType,
11346 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011347 UnqualifiedId TemplateName;
11348 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011349 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011350 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011351 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011352 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011353 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011354 /*EnteringContext=*/false,
11355 Template);
John McCall31f82722010-11-12 08:19:04 +000011356 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011357}
Mike Stump11289f42009-09-09 15:08:12 +000011358
Douglas Gregora16548e2009-08-11 05:31:07 +000011359template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011360TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011361TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011362 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011363 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011364 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011365 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011366 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011367 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011368 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011369 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011370 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011371 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011372 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011373 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011374 /*EnteringContext=*/false,
11375 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011376 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011377}
Chad Rosier1dcde962012-08-08 18:46:20 +000011378
Douglas Gregor71395fa2009-11-04 00:56:37 +000011379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011380ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011381TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11382 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011383 Expr *OrigCallee,
11384 Expr *First,
11385 Expr *Second) {
11386 Expr *Callee = OrigCallee->IgnoreParenCasts();
11387 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011388
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011389 if (First->getObjectKind() == OK_ObjCProperty) {
11390 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11391 if (BinaryOperator::isAssignmentOp(Opc))
11392 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11393 First, Second);
11394 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11395 if (Result.isInvalid())
11396 return ExprError();
11397 First = Result.get();
11398 }
11399
11400 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11401 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11402 if (Result.isInvalid())
11403 return ExprError();
11404 Second = Result.get();
11405 }
11406
Douglas Gregora16548e2009-08-11 05:31:07 +000011407 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011408 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011409 if (!First->getType()->isOverloadableType() &&
11410 !Second->getType()->isOverloadableType())
11411 return getSema().CreateBuiltinArraySubscriptExpr(First,
11412 Callee->getLocStart(),
11413 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011414 } else if (Op == OO_Arrow) {
11415 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011416 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11417 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011418 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011419 // The argument is not of overloadable type, so try to create a
11420 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011421 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011422 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011423
John McCallb268a282010-08-23 23:25:46 +000011424 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011425 }
11426 } else {
John McCallb268a282010-08-23 23:25:46 +000011427 if (!First->getType()->isOverloadableType() &&
11428 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011429 // Neither of the arguments is an overloadable type, so try to
11430 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011431 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011432 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011433 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011434 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011436
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011437 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011438 }
11439 }
Mike Stump11289f42009-09-09 15:08:12 +000011440
11441 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011442 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011443 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011444
John McCallb268a282010-08-23 23:25:46 +000011445 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011446 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011447 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011448 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011449 // If we've resolved this to a particular non-member function, just call
11450 // that function. If we resolved it to a member function,
11451 // CreateOverloaded* will find that function for us.
11452 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11453 if (!isa<CXXMethodDecl>(ND))
11454 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011455 }
Mike Stump11289f42009-09-09 15:08:12 +000011456
Douglas Gregora16548e2009-08-11 05:31:07 +000011457 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011458 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011459 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011460
Douglas Gregora16548e2009-08-11 05:31:07 +000011461 // Create the overloaded operator invocation for unary operators.
11462 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011463 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011464 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011465 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011466 }
Mike Stump11289f42009-09-09 15:08:12 +000011467
Douglas Gregore9d62932011-07-15 16:25:15 +000011468 if (Op == OO_Subscript) {
11469 SourceLocation LBrace;
11470 SourceLocation RBrace;
11471
11472 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011473 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011474 LBrace = SourceLocation::getFromRawEncoding(
11475 NameLoc.CXXOperatorName.BeginOpNameLoc);
11476 RBrace = SourceLocation::getFromRawEncoding(
11477 NameLoc.CXXOperatorName.EndOpNameLoc);
11478 } else {
11479 LBrace = Callee->getLocStart();
11480 RBrace = OpLoc;
11481 }
11482
11483 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11484 First, Second);
11485 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011486
Douglas Gregora16548e2009-08-11 05:31:07 +000011487 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011488 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011489 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011490 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11491 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011493
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011494 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011495}
Mike Stump11289f42009-09-09 15:08:12 +000011496
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011497template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011498ExprResult
John McCallb268a282010-08-23 23:25:46 +000011499TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011500 SourceLocation OperatorLoc,
11501 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011502 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011503 TypeSourceInfo *ScopeType,
11504 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011505 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011506 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011507 QualType BaseType = Base->getType();
11508 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011509 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011510 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011511 !BaseType->getAs<PointerType>()->getPointeeType()
11512 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011513 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011514 return SemaRef.BuildPseudoDestructorExpr(
11515 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11516 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011517 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011518
Douglas Gregor678f90d2010-02-25 01:56:36 +000011519 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011520 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11521 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11522 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11523 NameInfo.setNamedTypeInfo(DestroyedType);
11524
Richard Smith8e4a3862012-05-15 06:15:11 +000011525 // The scope type is now known to be a valid nested name specifier
11526 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011527 if (ScopeType) {
11528 if (!ScopeType->getType()->getAs<TagType>()) {
11529 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11530 diag::err_expected_class_or_namespace)
11531 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11532 return ExprError();
11533 }
11534 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11535 CCLoc);
11536 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011537
Abramo Bagnara7945c982012-01-27 09:46:47 +000011538 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011539 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011540 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011541 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011542 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011543 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011544 /*TemplateArgs*/ nullptr,
11545 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011546}
11547
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011548template<typename Derived>
11549StmtResult
11550TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011551 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011552 CapturedDecl *CD = S->getCapturedDecl();
11553 unsigned NumParams = CD->getNumParams();
11554 unsigned ContextParamPos = CD->getContextParamPosition();
11555 SmallVector<Sema::CapturedParamNameType, 4> Params;
11556 for (unsigned I = 0; I < NumParams; ++I) {
11557 if (I != ContextParamPos) {
11558 Params.push_back(
11559 std::make_pair(
11560 CD->getParam(I)->getName(),
11561 getDerived().TransformType(CD->getParam(I)->getType())));
11562 } else {
11563 Params.push_back(std::make_pair(StringRef(), QualType()));
11564 }
11565 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011566 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011567 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011568 StmtResult Body;
11569 {
11570 Sema::CompoundScopeRAII CompoundScope(getSema());
11571 Body = getDerived().TransformStmt(S->getCapturedStmt());
11572 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011573
11574 if (Body.isInvalid()) {
11575 getSema().ActOnCapturedRegionError();
11576 return StmtError();
11577 }
11578
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011579 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011580}
11581
Douglas Gregord6ff3322009-08-04 16:50:30 +000011582} // end namespace clang
11583
Hans Wennborg59dbe862015-09-29 20:56:43 +000011584#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H