blob: 176e57165ff39b8334e50b4e5627d996edeb1dab [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 Smith74aeef52013-04-26 16:15:35 +0000851 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
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.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000855 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
856 /*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) {
1651 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1652 EndLoc);
1653 }
1654
James Dennett2a4d13c2012-06-15 07:13:21 +00001655 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001656 ///
1657 /// By default, performs semantic analysis to build the new statement.
1658 /// Subclasses may override this routine to provide different behavior.
1659 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1660 Expr *object) {
1661 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1662 }
1663
James Dennett2a4d13c2012-06-15 07:13:21 +00001664 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001665 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001666 /// By default, performs semantic analysis to build the new statement.
1667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001669 Expr *Object, Stmt *Body) {
1670 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001671 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001672
James Dennett2a4d13c2012-06-15 07:13:21 +00001673 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001674 ///
1675 /// By default, performs semantic analysis to build the new statement.
1676 /// Subclasses may override this routine to provide different behavior.
1677 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1678 Stmt *Body) {
1679 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1680 }
John McCall53848232011-07-27 01:07:15 +00001681
Douglas Gregorf68a5082010-04-22 23:10:45 +00001682 /// \brief Build a new Objective-C fast enumeration statement.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001686 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001687 Stmt *Element,
1688 Expr *Collection,
1689 SourceLocation RParenLoc,
1690 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001691 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001692 Element,
John McCallb268a282010-08-23 23:25:46 +00001693 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001694 RParenLoc);
1695 if (ForEachStmt.isInvalid())
1696 return StmtError();
1697
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001698 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001699 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001700
Douglas Gregorebe10102009-08-20 07:17:43 +00001701 /// \brief Build a new C++ exception declaration.
1702 ///
1703 /// By default, performs semantic analysis to build the new decaration.
1704 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001705 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001706 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001707 SourceLocation StartLoc,
1708 SourceLocation IdLoc,
1709 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001710 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001711 StartLoc, IdLoc, Id);
1712 if (Var)
1713 getSema().CurContext->addDecl(Var);
1714 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001715 }
1716
1717 /// \brief Build a new C++ catch statement.
1718 ///
1719 /// By default, performs semantic analysis to build the new statement.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001722 VarDecl *ExceptionDecl,
1723 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001724 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1725 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001726 }
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregorebe10102009-08-20 07:17:43 +00001728 /// \brief Build a new C++ try statement.
1729 ///
1730 /// By default, performs semantic analysis to build the new statement.
1731 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001732 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1733 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001734 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Richard Smith02e85f32011-04-14 22:09:26 +00001737 /// \brief Build a new C++0x range-based for statement.
1738 ///
1739 /// By default, performs semantic analysis to build the new statement.
1740 /// Subclasses may override this routine to provide different behavior.
1741 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001742 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001743 SourceLocation ColonLoc,
1744 Stmt *Range, Stmt *BeginEnd,
1745 Expr *Cond, Expr *Inc,
1746 Stmt *LoopVar,
1747 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001748 // If we've just learned that the range is actually an Objective-C
1749 // collection, treat this as an Objective-C fast enumeration loop.
1750 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1751 if (RangeStmt->isSingleDecl()) {
1752 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001753 if (RangeVar->isInvalidDecl())
1754 return StmtError();
1755
Douglas Gregorf7106af2013-04-08 18:40:13 +00001756 Expr *RangeExpr = RangeVar->getInit();
1757 if (!RangeExpr->isTypeDependent() &&
1758 RangeExpr->getType()->isObjCObjectPointerType())
1759 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1760 RParenLoc);
1761 }
1762 }
1763 }
1764
Richard Smithcfd53b42015-10-22 06:13:50 +00001765 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1766 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001767 Cond, Inc, LoopVar, RParenLoc,
1768 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001769 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001770
1771 /// \brief Build a new C++0x range-based for statement.
1772 ///
1773 /// By default, performs semantic analysis to build the new statement.
1774 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001775 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001776 bool IsIfExists,
1777 NestedNameSpecifierLoc QualifierLoc,
1778 DeclarationNameInfo NameInfo,
1779 Stmt *Nested) {
1780 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1781 QualifierLoc, NameInfo, Nested);
1782 }
1783
Richard Smith02e85f32011-04-14 22:09:26 +00001784 /// \brief Attach body to a C++0x range-based for statement.
1785 ///
1786 /// By default, performs semantic analysis to finish the new statement.
1787 /// Subclasses may override this routine to provide different behavior.
1788 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1789 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001791
David Majnemerfad8f482013-10-15 09:33:02 +00001792 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001793 Stmt *TryBlock, Stmt *Handler) {
1794 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001795 }
1796
David Majnemerfad8f482013-10-15 09:33:02 +00001797 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001798 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001799 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001800 }
1801
David Majnemerfad8f482013-10-15 09:33:02 +00001802 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001803 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001804 }
1805
Alexey Bataevec474782014-10-09 08:45:04 +00001806 /// \brief Build a new predefined expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
1810 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1811 PredefinedExpr::IdentType IT) {
1812 return getSema().BuildPredefinedExpr(Loc, IT);
1813 }
1814
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 /// \brief Build a new expression that references a declaration.
1816 ///
1817 /// By default, performs semantic analysis to build the new expression.
1818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001819 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001820 LookupResult &R,
1821 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001822 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1823 }
1824
1825
1826 /// \brief Build a new expression that references a declaration.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001830 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001831 ValueDecl *VD,
1832 const DeclarationNameInfo &NameInfo,
1833 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001834 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001835 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001836
1837 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001838
1839 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001848 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
1850
Douglas Gregorad8a3362009-09-04 17:36:40 +00001851 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001856 SourceLocation OperatorLoc,
1857 bool isArrow,
1858 CXXScopeSpec &SS,
1859 TypeSourceInfo *ScopeType,
1860 SourceLocation CCLoc,
1861 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001862 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001865 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001868 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001869 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001870 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001871 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregor882211c2010-04-28 22:16:22 +00001874 /// \brief Build a new builtin offsetof expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001879 TypeSourceInfo *Type,
1880 ArrayRef<Sema::OffsetOfComponent> Components,
1881 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001882 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001883 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001885
1886 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001887 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001888 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001891 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1892 SourceLocation OpLoc,
1893 UnaryExprOrTypeTrait ExprKind,
1894 SourceRange R) {
1895 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
1897
Peter Collingbournee190dee2011-03-11 19:24:49 +00001898 /// \brief Build a new sizeof, alignof or vec step expression with an
1899 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001900 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001903 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1904 UnaryExprOrTypeTrait ExprKind,
1905 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001907 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001910
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001911 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 }
Mike Stump11289f42009-09-09 15:08:12 +00001913
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001915 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001920 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001922 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001923 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 RBracketLoc);
1925 }
1926
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001927 /// \brief Build a new array section expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1932 Expr *LowerBound,
1933 SourceLocation ColonLoc, Expr *Length,
1934 SourceLocation RBracketLoc) {
1935 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1936 ColonLoc, Length, RBracketLoc);
1937 }
1938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001945 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001946 Expr *ExecConfig = nullptr) {
1947 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001948 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 }
1950
1951 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001952 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001955 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001956 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001957 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001958 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001959 const DeclarationNameInfo &MemberNameInfo,
1960 ValueDecl *Member,
1961 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001962 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001963 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001964 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1965 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001966 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001967 // We have a reference to an unnamed field. This is always the
1968 // base of an anonymous struct/union member access, i.e. the
1969 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001970 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001971 assert(Member->getType()->isRecordType() &&
1972 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001973
Richard Smithcab9a7d2011-10-26 19:06:56 +00001974 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001975 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001976 QualifierLoc.getNestedNameSpecifier(),
1977 FoundDecl, Member);
1978 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001979 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001980 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001981 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001982 MemberExpr *ME = new (getSema().Context)
1983 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1984 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001985 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001988 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001989 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001990
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001991 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001992 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001993
John McCall16df1e52010-03-30 21:47:33 +00001994 // FIXME: this involves duplicating earlier analysis in a lot of
1995 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001996 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001997 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001998 R.resolveKind();
1999
John McCallb268a282010-08-23 23:25:46 +00002000 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002001 SS, TemplateKWLoc,
2002 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002003 R, ExplicitTemplateArgs,
2004 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 }
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002008 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002012 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002013 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002014 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
2016
2017 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002022 SourceLocation QuestionLoc,
2023 Expr *LHS,
2024 SourceLocation ColonLoc,
2025 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002026 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2027 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 }
2029
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002031 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002035 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002037 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002038 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002039 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002047 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002049 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002050 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002051 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 }
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002055 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation OpLoc,
2060 SourceLocation AccessorLoc,
2061 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002062
John McCall10eae182009-11-30 22:42:35 +00002063 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002064 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002065 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002066 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002067 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002068 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002069 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002070 /* TemplateArgs */ nullptr,
2071 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 }
Mike Stump11289f42009-09-09 15:08:12 +00002073
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002075 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002078 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002079 MultiExprArg Inits,
2080 SourceLocation RBraceLoc,
2081 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002082 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002083 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002084 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002085 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002086
Douglas Gregord3d93062009-11-09 17:16:50 +00002087 // Patch in the result type we were given, which may have been computed
2088 // when the initial InitListExpr was built.
2089 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2090 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002091 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002095 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002098 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 MultiExprArg ArrayExprs,
2100 SourceLocation EqualOrColonLoc,
2101 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002102 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002105 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002108
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002109 return Result;
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 value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// By default, builds the implicit value initialization without performing
2115 /// any semantic analysis. Subclasses may override this routine to provide
2116 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002117 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002118 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 }
Mike Stump11289f42009-09-09 15:08:12 +00002120
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002122 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002125 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002126 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002127 SourceLocation RParenLoc) {
2128 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002129 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002130 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
2132
2133 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002134 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002138 MultiExprArg SubExprs,
2139 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002140 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 }
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002144 ///
2145 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 /// rather than attempting to map the label statement itself.
2147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002148 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002149 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002150 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002154 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002157 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002158 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002160 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new __builtin_choose_expr expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002168 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RParenLoc) {
2170 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 RParenLoc);
2173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
Peter Collingbourne91147592011-04-15 00:35:48 +00002175 /// \brief Build a new generic selection expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
2179 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2180 SourceLocation DefaultLoc,
2181 SourceLocation RParenLoc,
2182 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002183 ArrayRef<TypeSourceInfo *> Types,
2184 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002185 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002186 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002187 }
2188
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 /// \brief Build a new overloaded operator call expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// The semantic analysis provides the behavior of template instantiation,
2193 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002194 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 /// argument-dependent lookup, etc. Subclasses may override this routine to
2196 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002199 Expr *Callee,
2200 Expr *First,
2201 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002202
2203 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// reinterpret_cast.
2205 ///
2206 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002207 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002209 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 Stmt::StmtClass Class,
2211 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002212 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 SourceLocation RAngleLoc,
2214 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002215 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation RParenLoc) {
2217 switch (Class) {
2218 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002219 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002220 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002221 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002222
2223 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002224 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002225 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002226 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002227
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002229 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002230 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002231 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002233
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002235 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002236 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002237 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002238
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002240 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 }
Mike Stump11289f42009-09-09 15:08:12 +00002243
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 /// \brief Build a new C++ static_cast expression.
2245 ///
2246 /// By default, performs semantic analysis to build the new expression.
2247 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002248 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002250 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 SourceLocation RAngleLoc,
2252 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002253 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002255 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002256 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002257 SourceRange(LAngleLoc, RAngleLoc),
2258 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 }
2260
2261 /// \brief Build a new C++ dynamic_cast expression.
2262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002265 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002267 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 SourceLocation RAngleLoc,
2269 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002270 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002272 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002273 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002274 SourceRange(LAngleLoc, RAngleLoc),
2275 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 }
2277
2278 /// \brief Build a new C++ reinterpret_cast expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002284 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 SourceLocation RAngleLoc,
2286 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002287 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002289 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002290 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002291 SourceRange(LAngleLoc, RAngleLoc),
2292 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 }
2294
2295 /// \brief Build a new C++ const_cast expression.
2296 ///
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002299 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002301 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 SourceLocation RAngleLoc,
2303 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002304 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002306 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002307 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002308 SourceRange(LAngleLoc, RAngleLoc),
2309 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 }
Mike Stump11289f42009-09-09 15:08:12 +00002311
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 /// \brief Build a new C++ functional-style cast expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002316 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2317 SourceLocation LParenLoc,
2318 Expr *Sub,
2319 SourceLocation RParenLoc) {
2320 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002321 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 RParenLoc);
2323 }
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 /// \brief Build a new C++ typeid(type) expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002330 SourceLocation TypeidLoc,
2331 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002333 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002334 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Francois Pichet9f4f2072010-09-08 12:20:18 +00002337
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 /// \brief Build a new C++ typeid(expr) expression.
2339 ///
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002342 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002343 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002346 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002347 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002348 }
2349
Francois Pichet9f4f2072010-09-08 12:20:18 +00002350 /// \brief Build a new C++ __uuidof(type) expression.
2351 ///
2352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
2354 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2355 SourceLocation TypeidLoc,
2356 TypeSourceInfo *Operand,
2357 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002358 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002359 RParenLoc);
2360 }
2361
2362 /// \brief Build a new C++ __uuidof(expr) expression.
2363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
2366 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2367 SourceLocation TypeidLoc,
2368 Expr *Operand,
2369 SourceLocation RParenLoc) {
2370 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2371 RParenLoc);
2372 }
2373
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 /// \brief Build a new C++ "this" expression.
2375 ///
2376 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002377 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002379 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002380 QualType ThisType,
2381 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002382 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002383 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 }
2385
2386 /// \brief Build a new C++ throw expression.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002390 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2391 bool IsThrownVariableInScope) {
2392 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 }
2394
2395 /// \brief Build a new C++ default-argument expression.
2396 ///
2397 /// By default, builds a new default-argument expression, which does not
2398 /// require any semantic analysis. Subclasses may override this routine to
2399 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002400 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002401 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002402 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 }
2404
Richard Smith852c9db2013-04-20 22:23:05 +00002405 /// \brief Build a new C++11 default-initialization expression.
2406 ///
2407 /// By default, builds a new default field initialization expression, which
2408 /// does not require any semantic analysis. Subclasses may override this
2409 /// routine to provide different behavior.
2410 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2411 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002412 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002413 }
2414
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 /// \brief Build a new C++ zero-initialization expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002419 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2420 SourceLocation LParenLoc,
2421 SourceLocation RParenLoc) {
2422 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002423 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 }
Mike Stump11289f42009-09-09 15:08:12 +00002425
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 /// \brief Build a new C++ "new" expression.
2427 ///
2428 /// By default, performs semantic analysis to build the new expression.
2429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002430 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002431 bool UseGlobal,
2432 SourceLocation PlacementLParen,
2433 MultiExprArg PlacementArgs,
2434 SourceLocation PlacementRParen,
2435 SourceRange TypeIdParens,
2436 QualType AllocatedType,
2437 TypeSourceInfo *AllocatedTypeInfo,
2438 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002439 SourceRange DirectInitRange,
2440 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002441 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002442 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002443 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002445 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002446 AllocatedType,
2447 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002448 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002449 DirectInitRange,
2450 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 }
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 /// \brief Build a new C++ "delete" expression.
2454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 bool IsGlobalDelete,
2459 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002460 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002462 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
Mike Stump11289f42009-09-09 15:08:12 +00002464
Douglas Gregor29c42f22012-02-24 07:38:34 +00002465 /// \brief Build a new type trait expression.
2466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
2469 ExprResult RebuildTypeTrait(TypeTrait Trait,
2470 SourceLocation StartLoc,
2471 ArrayRef<TypeSourceInfo *> Args,
2472 SourceLocation RParenLoc) {
2473 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002475
John Wiegley6242b6a2011-04-28 00:16:57 +00002476 /// \brief Build a new array type trait expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
2480 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2481 SourceLocation StartLoc,
2482 TypeSourceInfo *TSInfo,
2483 Expr *DimExpr,
2484 SourceLocation RParenLoc) {
2485 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2486 }
2487
John Wiegleyf9f65842011-04-25 06:54:41 +00002488 /// \brief Build a new expression trait expression.
2489 ///
2490 /// By default, performs semantic analysis to build the new expression.
2491 /// Subclasses may override this routine to provide different behavior.
2492 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2493 SourceLocation StartLoc,
2494 Expr *Queried,
2495 SourceLocation RParenLoc) {
2496 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2497 }
2498
Mike Stump11289f42009-09-09 15:08:12 +00002499 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 /// expression.
2501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002504 ExprResult RebuildDependentScopeDeclRefExpr(
2505 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002506 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002507 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002508 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002509 bool IsAddressOfOperand,
2510 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002511 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002512 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002513
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002514 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002515 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2516 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002517
Reid Kleckner32506ed2014-06-12 23:03:48 +00002518 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002519 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002520 }
2521
2522 /// \brief Build a new template-id expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002527 SourceLocation TemplateKWLoc,
2528 LookupResult &R,
2529 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002530 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002531 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2532 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 }
2534
2535 /// \brief Build a new object-construction expression.
2536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002539 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002540 SourceLocation Loc,
2541 CXXConstructorDecl *Constructor,
2542 bool IsElidable,
2543 MultiExprArg Args,
2544 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002545 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002546 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002547 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002548 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002549 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002550 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002551 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002552 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002553 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002554
Douglas Gregordb121ba2009-12-14 16:27:04 +00002555 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002556 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002557 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002558 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002559 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002560 RequiresZeroInit, ConstructKind,
2561 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002562 }
2563
2564 /// \brief Build a new object-construction expression.
2565 ///
2566 /// By default, performs semantic analysis to build the new expression.
2567 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002568 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2569 SourceLocation LParenLoc,
2570 MultiExprArg Args,
2571 SourceLocation RParenLoc) {
2572 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002574 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 RParenLoc);
2576 }
2577
2578 /// \brief Build a new object-construction expression.
2579 ///
2580 /// By default, performs semantic analysis to build the new expression.
2581 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002582 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2583 SourceLocation LParenLoc,
2584 MultiExprArg Args,
2585 SourceLocation RParenLoc) {
2586 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002588 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 RParenLoc);
2590 }
Mike Stump11289f42009-09-09 15:08:12 +00002591
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 /// \brief Build a new member reference 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 RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002597 QualType BaseType,
2598 bool IsArrow,
2599 SourceLocation OperatorLoc,
2600 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002601 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002602 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002603 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002604 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002606 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002607
John McCallb268a282010-08-23 23:25:46 +00002608 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002609 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002610 SS, TemplateKWLoc,
2611 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002612 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002613 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 }
2615
John McCall10eae182009-11-30 22:42:35 +00002616 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002620 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2621 SourceLocation OperatorLoc,
2622 bool IsArrow,
2623 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002624 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002625 NamedDecl *FirstQualifierInScope,
2626 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002627 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002628 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002629 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002630
John McCallb268a282010-08-23 23:25:46 +00002631 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002632 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002633 SS, TemplateKWLoc,
2634 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002635 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002636 }
Mike Stump11289f42009-09-09 15:08:12 +00002637
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002638 /// \brief Build a new noexcept expression.
2639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
2642 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2643 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2644 }
2645
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002646 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002647 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2648 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002649 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002650 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002651 Optional<unsigned> Length,
2652 ArrayRef<TemplateArgument> PartialArgs) {
2653 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2654 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002655 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002656
Patrick Beard0caa3942012-04-19 00:25:12 +00002657 /// \brief Build a new Objective-C boxed expression.
2658 ///
2659 /// By default, performs semantic analysis to build the new expression.
2660 /// Subclasses may override this routine to provide different behavior.
2661 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2662 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2663 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002664
Ted Kremeneke65b0862012-03-06 20:05:56 +00002665 /// \brief Build a new Objective-C array literal.
2666 ///
2667 /// By default, performs semantic analysis to build the new expression.
2668 /// Subclasses may override this routine to provide different behavior.
2669 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2670 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002671 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002672 MultiExprArg(Elements, NumElements));
2673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002674
2675 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002676 Expr *Base, Expr *Key,
2677 ObjCMethodDecl *getterMethod,
2678 ObjCMethodDecl *setterMethod) {
2679 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2680 getterMethod, setterMethod);
2681 }
2682
2683 /// \brief Build a new Objective-C dictionary literal.
2684 ///
2685 /// By default, performs semantic analysis to build the new expression.
2686 /// Subclasses may override this routine to provide different behavior.
2687 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2688 ObjCDictionaryElement *Elements,
2689 unsigned NumElements) {
2690 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002692
James Dennett2a4d13c2012-06-15 07:13:21 +00002693 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002694 ///
2695 /// By default, performs semantic analysis to build the new expression.
2696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002697 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002698 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002699 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002700 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002701 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002702
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002703 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002704 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002705 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002706 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002707 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002708 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002709 MultiExprArg Args,
2710 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002711 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2712 ReceiverTypeInfo->getType(),
2713 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002714 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002715 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002716 }
2717
2718 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002720 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002721 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002722 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002723 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002724 MultiExprArg Args,
2725 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002726 return SemaRef.BuildInstanceMessage(Receiver,
2727 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002728 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002729 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002730 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002731 }
2732
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002733 /// \brief Build a new Objective-C instance/class message to 'super'.
2734 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2735 Selector Sel,
2736 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002737 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002738 ObjCMethodDecl *Method,
2739 SourceLocation LBracLoc,
2740 MultiExprArg Args,
2741 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002742 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002743 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002744 SuperLoc,
2745 Sel, Method, LBracLoc, SelectorLocs,
2746 RBracLoc, Args)
2747 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002748 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002749 SuperLoc,
2750 Sel, Method, LBracLoc, SelectorLocs,
2751 RBracLoc, Args);
2752
2753
2754 }
2755
Douglas Gregord51d90d2010-04-26 20:11:03 +00002756 /// \brief Build a new Objective-C ivar reference expression.
2757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002760 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002761 SourceLocation IvarLoc,
2762 bool IsArrow, bool IsFreeIvar) {
2763 // FIXME: We lose track of the IsFreeIvar bit.
2764 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002765 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2766 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002767 /*FIXME:*/IvarLoc, IsArrow,
2768 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002769 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002770 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002771 /*TemplateArgs=*/nullptr,
2772 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002773 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002774
2775 /// \brief Build a new Objective-C property reference expression.
2776 ///
2777 /// By default, performs semantic analysis to build the new expression.
2778 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002779 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002780 ObjCPropertyDecl *Property,
2781 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002782 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002783 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2784 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2785 /*FIXME:*/PropertyLoc,
2786 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002787 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002788 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002789 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002790 /*TemplateArgs=*/nullptr,
2791 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
John McCallb7bd14f2010-12-02 01:19:52 +00002794 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002795 ///
2796 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002797 /// Subclasses may override this routine to provide different behavior.
2798 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2799 ObjCMethodDecl *Getter,
2800 ObjCMethodDecl *Setter,
2801 SourceLocation PropertyLoc) {
2802 // Since these expressions can only be value-dependent, we do not
2803 // need to perform semantic analysis again.
2804 return Owned(
2805 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2806 VK_LValue, OK_ObjCProperty,
2807 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002808 }
2809
Douglas Gregord51d90d2010-04-26 20:11:03 +00002810 /// \brief Build a new Objective-C "isa" expression.
2811 ///
2812 /// By default, performs semantic analysis to build the new expression.
2813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002814 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002815 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002816 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002817 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2818 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002819 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002820 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002821 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002822 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002823 /*TemplateArgs=*/nullptr,
2824 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002826
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 /// \brief Build a new shuffle vector expression.
2828 ///
2829 /// By default, performs semantic analysis to build the new expression.
2830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002831 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002832 MultiExprArg SubExprs,
2833 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002834 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002835 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002836 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2837 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2838 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002839 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002840
Douglas Gregora16548e2009-08-11 05:31:07 +00002841 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002842 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002843 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2844 SemaRef.Context.BuiltinFnTy,
2845 VK_RValue, BuiltinLoc);
2846 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2847 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002848 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002849
2850 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002851 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002852 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002853 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002854
Douglas Gregora16548e2009-08-11 05:31:07 +00002855 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002856 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002857 }
John McCall31f82722010-11-12 08:19:04 +00002858
Hal Finkelc4d7c822013-09-18 03:29:45 +00002859 /// \brief Build a new convert vector expression.
2860 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2861 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2862 SourceLocation RParenLoc) {
2863 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2864 BuiltinLoc, RParenLoc);
2865 }
2866
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002867 /// \brief Build a new template argument pack expansion.
2868 ///
2869 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002870 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002871 /// different behavior.
2872 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002873 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002874 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002875 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002876 case TemplateArgument::Expression: {
2877 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002878 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2879 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002880 if (Result.isInvalid())
2881 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002882
Douglas Gregor98318c22011-01-03 21:37:45 +00002883 return TemplateArgumentLoc(Result.get(), Result.get());
2884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002885
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002886 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002887 return TemplateArgumentLoc(TemplateArgument(
2888 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002889 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002890 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002891 Pattern.getTemplateNameLoc(),
2892 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002893
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002894 case TemplateArgument::Null:
2895 case TemplateArgument::Integral:
2896 case TemplateArgument::Declaration:
2897 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002898 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002899 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002900 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002901
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002902 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002903 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002904 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002905 EllipsisLoc,
2906 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002907 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2908 Expansion);
2909 break;
2910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002911
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002912 return TemplateArgumentLoc();
2913 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
Douglas Gregor968f23a2011-01-03 19:31:53 +00002915 /// \brief Build a new expression pack expansion.
2916 ///
2917 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002919 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002920 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002921 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002922 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002923 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002924
Richard Smith0f0af192014-11-08 05:07:16 +00002925 /// \brief Build a new C++1z fold-expression.
2926 ///
2927 /// By default, performs semantic analysis in order to build a new fold
2928 /// expression.
2929 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2930 BinaryOperatorKind Operator,
2931 SourceLocation EllipsisLoc, Expr *RHS,
2932 SourceLocation RParenLoc) {
2933 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2934 RHS, RParenLoc);
2935 }
2936
2937 /// \brief Build an empty C++1z fold-expression with the given operator.
2938 ///
2939 /// By default, produces the fallback value for the fold-expression, or
2940 /// produce an error if there is no fallback value.
2941 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2942 BinaryOperatorKind Operator) {
2943 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2944 }
2945
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002946 /// \brief Build a new atomic operation expression.
2947 ///
2948 /// By default, performs semantic analysis to build the new expression.
2949 /// Subclasses may override this routine to provide different behavior.
2950 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2951 MultiExprArg SubExprs,
2952 QualType RetTy,
2953 AtomicExpr::AtomicOp Op,
2954 SourceLocation RParenLoc) {
2955 // Just create the expression; there is not any interesting semantic
2956 // analysis here because we can't actually build an AtomicExpr until
2957 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002958 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002959 RParenLoc);
2960 }
2961
John McCall31f82722010-11-12 08:19:04 +00002962private:
Douglas Gregor14454802011-02-25 02:25:35 +00002963 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2964 QualType ObjectType,
2965 NamedDecl *FirstQualifierInScope,
2966 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002967
2968 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2969 QualType ObjectType,
2970 NamedDecl *FirstQualifierInScope,
2971 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002972
2973 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2974 NamedDecl *FirstQualifierInScope,
2975 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976};
Douglas Gregora16548e2009-08-11 05:31:07 +00002977
Douglas Gregorebe10102009-08-20 07:17:43 +00002978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002979StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002980 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002981 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregorebe10102009-08-20 07:17:43 +00002983 switch (S->getStmtClass()) {
2984 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002985
Douglas Gregorebe10102009-08-20 07:17:43 +00002986 // Transform individual statement nodes
2987#define STMT(Node, Parent) \
2988 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002989#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002990#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002991#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002992
Douglas Gregorebe10102009-08-20 07:17:43 +00002993 // Transform expressions by calling TransformExpr.
2994#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002995#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002996#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002997#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002998 {
John McCalldadc5752010-08-24 06:29:42 +00002999 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003000 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003001 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003002
Richard Smith945f8d32013-01-14 22:39:08 +00003003 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003004 }
Mike Stump11289f42009-09-09 15:08:12 +00003005 }
3006
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003007 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003008}
Mike Stump11289f42009-09-09 15:08:12 +00003009
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003010template<typename Derived>
3011OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3012 if (!S)
3013 return S;
3014
3015 switch (S->getClauseKind()) {
3016 default: break;
3017 // Transform individual clause nodes
3018#define OPENMP_CLAUSE(Name, Class) \
3019 case OMPC_ ## Name : \
3020 return getDerived().Transform ## Class(cast<Class>(S));
3021#include "clang/Basic/OpenMPKinds.def"
3022 }
3023
3024 return S;
3025}
3026
Mike Stump11289f42009-09-09 15:08:12 +00003027
Douglas Gregore922c772009-08-04 22:27:00 +00003028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003029ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003030 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003031 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003032
3033 switch (E->getStmtClass()) {
3034 case Stmt::NoStmtClass: break;
3035#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003036#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003037#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003038 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003040 }
3041
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003042 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003043}
3044
3045template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003046ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003047 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003048 // Initializers are instantiated like expressions, except that various outer
3049 // layers are stripped.
3050 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003051 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003052
3053 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3054 Init = ExprTemp->getSubExpr();
3055
Richard Smithe6ca4752013-05-30 22:40:16 +00003056 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3057 Init = MTE->GetTemporaryExpr();
3058
Richard Smithd59b8322012-12-19 01:39:02 +00003059 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3060 Init = Binder->getSubExpr();
3061
3062 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3063 Init = ICE->getSubExprAsWritten();
3064
Richard Smithcc1b96d2013-06-12 22:31:48 +00003065 if (CXXStdInitializerListExpr *ILE =
3066 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003067 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003068
Richard Smithc6abd962014-07-25 01:12:44 +00003069 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003070 // InitListExprs. Other forms of copy-initialization will be a no-op if
3071 // the initializer is already the right type.
3072 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003073 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003074 return getDerived().TransformExpr(Init);
3075
3076 // Revert value-initialization back to empty parens.
3077 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3078 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003079 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003080 Parens.getEnd());
3081 }
3082
3083 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3084 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003085 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003086 SourceLocation());
3087
3088 // Revert initialization by constructor back to a parenthesized or braced list
3089 // of expressions. Any other form of initializer can just be reused directly.
3090 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003091 return getDerived().TransformExpr(Init);
3092
Richard Smithf8adcdc2014-07-17 05:12:35 +00003093 // If the initialization implicitly converted an initializer list to a
3094 // std::initializer_list object, unwrap the std::initializer_list too.
3095 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003096 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003097
Richard Smithd59b8322012-12-19 01:39:02 +00003098 SmallVector<Expr*, 8> NewArgs;
3099 bool ArgChanged = false;
3100 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003101 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003102 return ExprError();
3103
3104 // If this was list initialization, revert to list form.
3105 if (Construct->isListInitialization())
3106 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3107 Construct->getLocEnd(),
3108 Construct->getType());
3109
Richard Smithd59b8322012-12-19 01:39:02 +00003110 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003111 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003112 if (Parens.isInvalid()) {
3113 // This was a variable declaration's initialization for which no initializer
3114 // was specified.
3115 assert(NewArgs.empty() &&
3116 "no parens or braces but have direct init with arguments?");
3117 return ExprEmpty();
3118 }
Richard Smithd59b8322012-12-19 01:39:02 +00003119 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3120 Parens.getEnd());
3121}
3122
3123template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003124bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3125 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003126 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003127 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003128 bool *ArgChanged) {
3129 for (unsigned I = 0; I != NumInputs; ++I) {
3130 // If requested, drop call arguments that need to be dropped.
3131 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3132 if (ArgChanged)
3133 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregora3efea12011-01-03 19:04:46 +00003135 break;
3136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003137
Douglas Gregor968f23a2011-01-03 19:31:53 +00003138 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3139 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Chris Lattner01cf8db2011-07-20 06:58:45 +00003141 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003142 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3143 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Douglas Gregor968f23a2011-01-03 19:31:53 +00003145 // Determine whether the set of unexpanded parameter packs can and should
3146 // be expanded.
3147 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003148 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003149 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3150 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003151 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3152 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003153 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003154 Expand, RetainExpansion,
3155 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003156 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor968f23a2011-01-03 19:31:53 +00003158 if (!Expand) {
3159 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003160 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003161 // expansion.
3162 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3163 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3164 if (OutPattern.isInvalid())
3165 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
3167 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003168 Expansion->getEllipsisLoc(),
3169 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003170 if (Out.isInvalid())
3171 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor968f23a2011-01-03 19:31:53 +00003173 if (ArgChanged)
3174 *ArgChanged = true;
3175 Outputs.push_back(Out.get());
3176 continue;
3177 }
John McCall542e7c62011-07-06 07:30:07 +00003178
3179 // Record right away that the argument was changed. This needs
3180 // to happen even if the array expands to nothing.
3181 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor968f23a2011-01-03 19:31:53 +00003183 // The transform has determined that we should perform an elementwise
3184 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003185 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003186 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3187 ExprResult Out = getDerived().TransformExpr(Pattern);
3188 if (Out.isInvalid())
3189 return true;
3190
Richard Smith9467be42014-06-06 17:33:35 +00003191 // FIXME: Can this happen? We should not try to expand the pack
3192 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003193 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003194 Out = getDerived().RebuildPackExpansion(
3195 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003196 if (Out.isInvalid())
3197 return true;
3198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003199
Douglas Gregor968f23a2011-01-03 19:31:53 +00003200 Outputs.push_back(Out.get());
3201 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
Richard Smith9467be42014-06-06 17:33:35 +00003203 // If we're supposed to retain a pack expansion, do so by temporarily
3204 // forgetting the partially-substituted parameter pack.
3205 if (RetainExpansion) {
3206 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3207
3208 ExprResult Out = getDerived().TransformExpr(Pattern);
3209 if (Out.isInvalid())
3210 return true;
3211
3212 Out = getDerived().RebuildPackExpansion(
3213 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3214 if (Out.isInvalid())
3215 return true;
3216
3217 Outputs.push_back(Out.get());
3218 }
3219
Douglas Gregor968f23a2011-01-03 19:31:53 +00003220 continue;
3221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Richard Smithd59b8322012-12-19 01:39:02 +00003223 ExprResult Result =
3224 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3225 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003226 if (Result.isInvalid())
3227 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003228
Douglas Gregora3efea12011-01-03 19:04:46 +00003229 if (Result.get() != Inputs[I] && ArgChanged)
3230 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
3232 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003234
Douglas Gregora3efea12011-01-03 19:04:46 +00003235 return false;
3236}
3237
3238template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003239NestedNameSpecifierLoc
3240TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3241 NestedNameSpecifierLoc NNS,
3242 QualType ObjectType,
3243 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003244 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003245 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003246 Qualifier = Qualifier.getPrefix())
3247 Qualifiers.push_back(Qualifier);
3248
3249 CXXScopeSpec SS;
3250 while (!Qualifiers.empty()) {
3251 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3252 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregor14454802011-02-25 02:25:35 +00003254 switch (QNNS->getKind()) {
3255 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003256 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003257 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003258 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003259 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003260 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003261 FirstQualifierInScope, false))
3262 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003263
Douglas Gregor14454802011-02-25 02:25:35 +00003264 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor14454802011-02-25 02:25:35 +00003266 case NestedNameSpecifier::Namespace: {
3267 NamespaceDecl *NS
3268 = cast_or_null<NamespaceDecl>(
3269 getDerived().TransformDecl(
3270 Q.getLocalBeginLoc(),
3271 QNNS->getAsNamespace()));
3272 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3273 break;
3274 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003275
Douglas Gregor14454802011-02-25 02:25:35 +00003276 case NestedNameSpecifier::NamespaceAlias: {
3277 NamespaceAliasDecl *Alias
3278 = cast_or_null<NamespaceAliasDecl>(
3279 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3280 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003281 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003282 Q.getLocalEndLoc());
3283 break;
3284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor14454802011-02-25 02:25:35 +00003286 case NestedNameSpecifier::Global:
3287 // There is no meaningful transformation that one could perform on the
3288 // global scope.
3289 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3290 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
Nikola Smiljanic67860242014-09-26 00:28:20 +00003292 case NestedNameSpecifier::Super: {
3293 CXXRecordDecl *RD =
3294 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3295 SourceLocation(), QNNS->getAsRecordDecl()));
3296 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3297 break;
3298 }
3299
Douglas Gregor14454802011-02-25 02:25:35 +00003300 case NestedNameSpecifier::TypeSpecWithTemplate:
3301 case NestedNameSpecifier::TypeSpec: {
3302 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3303 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregor14454802011-02-25 02:25:35 +00003305 if (!TL)
3306 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003307
Douglas Gregor14454802011-02-25 02:25:35 +00003308 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003309 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003310 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003311 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003312 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003313 if (TL.getType()->isEnumeralType())
3314 SemaRef.Diag(TL.getBeginLoc(),
3315 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003316 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3317 Q.getLocalEndLoc());
3318 break;
3319 }
Richard Trieude756fb2011-05-07 01:36:37 +00003320 // If the nested-name-specifier is an invalid type def, don't emit an
3321 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003322 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3323 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003324 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003325 << TL.getType() << SS.getRange();
3326 }
Douglas Gregor14454802011-02-25 02:25:35 +00003327 return NestedNameSpecifierLoc();
3328 }
Douglas Gregore16af532011-02-28 18:50:33 +00003329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregore16af532011-02-28 18:50:33 +00003331 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003332 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003333 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003334 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor14454802011-02-25 02:25:35 +00003336 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003337 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003338 !getDerived().AlwaysRebuild())
3339 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
3341 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003342 // nested-name-specifier, do so.
3343 if (SS.location_size() == NNS.getDataLength() &&
3344 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3345 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3346
3347 // Allocate new nested-name-specifier location information.
3348 return SS.getWithLocInContext(SemaRef.Context);
3349}
3350
3351template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003352DeclarationNameInfo
3353TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003354::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003355 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003356 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003357 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003358
3359 switch (Name.getNameKind()) {
3360 case DeclarationName::Identifier:
3361 case DeclarationName::ObjCZeroArgSelector:
3362 case DeclarationName::ObjCOneArgSelector:
3363 case DeclarationName::ObjCMultiArgSelector:
3364 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003365 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003366 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003367 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregorf816bd72009-09-03 22:13:48 +00003369 case DeclarationName::CXXConstructorName:
3370 case DeclarationName::CXXDestructorName:
3371 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003372 TypeSourceInfo *NewTInfo;
3373 CanQualType NewCanTy;
3374 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003375 NewTInfo = getDerived().TransformType(OldTInfo);
3376 if (!NewTInfo)
3377 return DeclarationNameInfo();
3378 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003379 }
3380 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003381 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003382 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003383 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003384 if (NewT.isNull())
3385 return DeclarationNameInfo();
3386 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3387 }
Mike Stump11289f42009-09-09 15:08:12 +00003388
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003389 DeclarationName NewName
3390 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3391 NewCanTy);
3392 DeclarationNameInfo NewNameInfo(NameInfo);
3393 NewNameInfo.setName(NewName);
3394 NewNameInfo.setNamedTypeInfo(NewTInfo);
3395 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003396 }
Mike Stump11289f42009-09-09 15:08:12 +00003397 }
3398
David Blaikie83d382b2011-09-23 05:06:16 +00003399 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003400}
3401
3402template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003403TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003404TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3405 TemplateName Name,
3406 SourceLocation NameLoc,
3407 QualType ObjectType,
3408 NamedDecl *FirstQualifierInScope) {
3409 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3410 TemplateDecl *Template = QTN->getTemplateDecl();
3411 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor9db53502011-03-02 18:07:45 +00003413 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003414 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003415 Template));
3416 if (!TransTemplate)
3417 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor9db53502011-03-02 18:07:45 +00003419 if (!getDerived().AlwaysRebuild() &&
3420 SS.getScopeRep() == QTN->getQualifier() &&
3421 TransTemplate == Template)
3422 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor9db53502011-03-02 18:07:45 +00003424 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3425 TransTemplate);
3426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor9db53502011-03-02 18:07:45 +00003428 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3429 if (SS.getScopeRep()) {
3430 // These apply to the scope specifier, not the template.
3431 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003432 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003433 }
3434
Douglas Gregor9db53502011-03-02 18:07:45 +00003435 if (!getDerived().AlwaysRebuild() &&
3436 SS.getScopeRep() == DTN->getQualifier() &&
3437 ObjectType.isNull())
3438 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor9db53502011-03-02 18:07:45 +00003440 if (DTN->isIdentifier()) {
3441 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003442 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003443 NameLoc,
3444 ObjectType,
3445 FirstQualifierInScope);
3446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor9db53502011-03-02 18:07:45 +00003448 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3449 ObjectType);
3450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor9db53502011-03-02 18:07:45 +00003452 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3453 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003454 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003455 Template));
3456 if (!TransTemplate)
3457 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003458
Douglas Gregor9db53502011-03-02 18:07:45 +00003459 if (!getDerived().AlwaysRebuild() &&
3460 TransTemplate == Template)
3461 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregor9db53502011-03-02 18:07:45 +00003463 return TemplateName(TransTemplate);
3464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003465
Douglas Gregor9db53502011-03-02 18:07:45 +00003466 if (SubstTemplateTemplateParmPackStorage *SubstPack
3467 = Name.getAsSubstTemplateTemplateParmPack()) {
3468 TemplateTemplateParmDecl *TransParam
3469 = cast_or_null<TemplateTemplateParmDecl>(
3470 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3471 if (!TransParam)
3472 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregor9db53502011-03-02 18:07:45 +00003474 if (!getDerived().AlwaysRebuild() &&
3475 TransParam == SubstPack->getParameterPack())
3476 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
3478 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003479 SubstPack->getArgumentPack());
3480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003481
Douglas Gregor9db53502011-03-02 18:07:45 +00003482 // These should be getting filtered out before they reach the AST.
3483 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003484}
3485
3486template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003487void TreeTransform<Derived>::InventTemplateArgumentLoc(
3488 const TemplateArgument &Arg,
3489 TemplateArgumentLoc &Output) {
3490 SourceLocation Loc = getDerived().getBaseLocation();
3491 switch (Arg.getKind()) {
3492 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003493 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003494 break;
3495
3496 case TemplateArgument::Type:
3497 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003498 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
John McCall0ad16662009-10-29 08:12:44 +00003500 break;
3501
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003502 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003503 case TemplateArgument::TemplateExpansion: {
3504 NestedNameSpecifierLocBuilder Builder;
3505 TemplateName Template = Arg.getAsTemplate();
3506 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3507 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3508 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3509 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Douglas Gregor9d802122011-03-02 17:09:35 +00003511 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003512 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003513 Builder.getWithLocInContext(SemaRef.Context),
3514 Loc);
3515 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003516 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003517 Builder.getWithLocInContext(SemaRef.Context),
3518 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003520 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003521 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003522
John McCall0ad16662009-10-29 08:12:44 +00003523 case TemplateArgument::Expression:
3524 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3525 break;
3526
3527 case TemplateArgument::Declaration:
3528 case TemplateArgument::Integral:
3529 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003530 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003531 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003532 break;
3533 }
3534}
3535
3536template<typename Derived>
3537bool TreeTransform<Derived>::TransformTemplateArgument(
3538 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003539 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003540 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003541 switch (Arg.getKind()) {
3542 case TemplateArgument::Null:
3543 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003544 case TemplateArgument::Pack:
3545 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003546 case TemplateArgument::NullPtr:
3547 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregore922c772009-08-04 22:27:00 +00003549 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003550 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003551 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003552 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003553
3554 DI = getDerived().TransformType(DI);
3555 if (!DI) return true;
3556
3557 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3558 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003559 }
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003561 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003562 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3563 if (QualifierLoc) {
3564 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3565 if (!QualifierLoc)
3566 return true;
3567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003568
Douglas Gregordf846d12011-03-02 18:46:51 +00003569 CXXScopeSpec SS;
3570 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003571 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003572 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3573 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003574 if (Template.isNull())
3575 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor9d802122011-03-02 17:09:35 +00003577 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003578 Input.getTemplateNameLoc());
3579 return false;
3580 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003581
3582 case TemplateArgument::TemplateExpansion:
3583 llvm_unreachable("Caller should expand pack expansions");
3584
Douglas Gregore922c772009-08-04 22:27:00 +00003585 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003586 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003587 EnterExpressionEvaluationContext Unevaluated(
3588 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003589
John McCall0ad16662009-10-29 08:12:44 +00003590 Expr *InputExpr = Input.getSourceExpression();
3591 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3592
Chris Lattnercdb591a2011-04-25 20:37:58 +00003593 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003594 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003595 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003596 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003597 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003598 }
Douglas Gregore922c772009-08-04 22:27:00 +00003599 }
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregore922c772009-08-04 22:27:00 +00003601 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003602 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003603}
3604
Douglas Gregorfe921a72010-12-20 23:36:19 +00003605/// \brief Iterator adaptor that invents template argument location information
3606/// for each of the template arguments in its underlying iterator.
3607template<typename Derived, typename InputIterator>
3608class TemplateArgumentLocInventIterator {
3609 TreeTransform<Derived> &Self;
3610 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregorfe921a72010-12-20 23:36:19 +00003612public:
3613 typedef TemplateArgumentLoc value_type;
3614 typedef TemplateArgumentLoc reference;
3615 typedef typename std::iterator_traits<InputIterator>::difference_type
3616 difference_type;
3617 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregorfe921a72010-12-20 23:36:19 +00003619 class pointer {
3620 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
Douglas Gregorfe921a72010-12-20 23:36:19 +00003622 public:
3623 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Douglas Gregorfe921a72010-12-20 23:36:19 +00003625 const TemplateArgumentLoc *operator->() const { return &Arg; }
3626 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003628 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003629
Douglas Gregorfe921a72010-12-20 23:36:19 +00003630 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3631 InputIterator Iter)
3632 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003633
Douglas Gregorfe921a72010-12-20 23:36:19 +00003634 TemplateArgumentLocInventIterator &operator++() {
3635 ++Iter;
3636 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregorfe921a72010-12-20 23:36:19 +00003639 TemplateArgumentLocInventIterator operator++(int) {
3640 TemplateArgumentLocInventIterator Old(*this);
3641 ++(*this);
3642 return Old;
3643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregorfe921a72010-12-20 23:36:19 +00003645 reference operator*() const {
3646 TemplateArgumentLoc Result;
3647 Self.InventTemplateArgumentLoc(*Iter, Result);
3648 return Result;
3649 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregorfe921a72010-12-20 23:36:19 +00003651 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
Douglas Gregorfe921a72010-12-20 23:36:19 +00003653 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3654 const TemplateArgumentLocInventIterator &Y) {
3655 return X.Iter == Y.Iter;
3656 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003657
Douglas Gregorfe921a72010-12-20 23:36:19 +00003658 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3659 const TemplateArgumentLocInventIterator &Y) {
3660 return X.Iter != Y.Iter;
3661 }
3662};
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor42cafa82010-12-20 17:42:22 +00003664template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003665template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003666bool TreeTransform<Derived>::TransformTemplateArguments(
3667 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3668 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003669 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003670 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003671 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3674 // Unpack argument packs, which we translate them into separate
3675 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003676 // FIXME: We could do much better if we could guarantee that the
3677 // TemplateArgumentLocInfo for the pack expansion would be usable for
3678 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003679 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003680 TemplateArgument::pack_iterator>
3681 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003682 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003683 In.getArgument().pack_begin()),
3684 PackLocIterator(*this,
3685 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003686 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003687 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003689 continue;
3690 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 if (In.getArgument().isPackExpansion()) {
3693 // We have a pack expansion, for which we will be substituting into
3694 // the pattern.
3695 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003696 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003697 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003698 = getSema().getTemplateArgumentPackExpansionPattern(
3699 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
Chris Lattner01cf8db2011-07-20 06:58:45 +00003701 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003702 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3703 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003704
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003705 // Determine whether the set of unexpanded parameter packs can and should
3706 // be expanded.
3707 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003708 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003709 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003710 if (getDerived().TryExpandParameterPacks(Ellipsis,
3711 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003712 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003713 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003714 RetainExpansion,
3715 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003718 if (!Expand) {
3719 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003720 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003721 // expansion.
3722 TemplateArgumentLoc OutPattern;
3723 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003724 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003725 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003726
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003727 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3728 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003729 if (Out.getArgument().isNull())
3730 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003731
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003732 Outputs.addArgument(Out);
3733 continue;
3734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003735
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003736 // The transform has determined that we should perform an elementwise
3737 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003738 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003739 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3740
Richard Smithd784e682015-09-23 21:41:42 +00003741 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003742 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003744 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003745 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3746 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003747 if (Out.getArgument().isNull())
3748 return true;
3749 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003750
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003751 Outputs.addArgument(Out);
3752 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003753
Douglas Gregor48d24112011-01-10 20:53:55 +00003754 // If we're supposed to retain a pack expansion, do so by temporarily
3755 // forgetting the partially-substituted parameter pack.
3756 if (RetainExpansion) {
3757 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
Richard Smithd784e682015-09-23 21:41:42 +00003759 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003760 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003762 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3763 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003764 if (Out.getArgument().isNull())
3765 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor48d24112011-01-10 20:53:55 +00003767 Outputs.addArgument(Out);
3768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003770 continue;
3771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
3773 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003774 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003775 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
Douglas Gregor42cafa82010-12-20 17:42:22 +00003777 Outputs.addArgument(Out);
3778 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003779
Douglas Gregor42cafa82010-12-20 17:42:22 +00003780 return false;
3781
3782}
3783
Douglas Gregord6ff3322009-08-04 16:50:30 +00003784//===----------------------------------------------------------------------===//
3785// Type transformation
3786//===----------------------------------------------------------------------===//
3787
3788template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003789QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003790 if (getDerived().AlreadyTransformed(T))
3791 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003792
John McCall550e0c22009-10-21 00:40:46 +00003793 // Temporary workaround. All of these transformations should
3794 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003795 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3796 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003797
John McCall31f82722010-11-12 08:19:04 +00003798 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003799
John McCall550e0c22009-10-21 00:40:46 +00003800 if (!NewDI)
3801 return QualType();
3802
3803 return NewDI->getType();
3804}
3805
3806template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003807TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003808 // Refine the base location to the type's location.
3809 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3810 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003811 if (getDerived().AlreadyTransformed(DI->getType()))
3812 return DI;
3813
3814 TypeLocBuilder TLB;
3815
3816 TypeLoc TL = DI->getTypeLoc();
3817 TLB.reserve(TL.getFullDataSize());
3818
John McCall31f82722010-11-12 08:19:04 +00003819 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003820 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003821 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003822
John McCallbcd03502009-12-07 02:54:59 +00003823 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003824}
3825
3826template<typename Derived>
3827QualType
John McCall31f82722010-11-12 08:19:04 +00003828TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003829 switch (T.getTypeLocClass()) {
3830#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003831#define TYPELOC(CLASS, PARENT) \
3832 case TypeLoc::CLASS: \
3833 return getDerived().Transform##CLASS##Type(TLB, \
3834 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003835#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003836 }
Mike Stump11289f42009-09-09 15:08:12 +00003837
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003838 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003839}
3840
3841/// FIXME: By default, this routine adds type qualifiers only to types
3842/// that can have qualifiers, and silently suppresses those qualifiers
3843/// that are not permitted (e.g., qualifiers on reference or function
3844/// types). This is the right thing for template instantiation, but
3845/// probably not for other clients.
3846template<typename Derived>
3847QualType
3848TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003849 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003850 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003851
John McCall31f82722010-11-12 08:19:04 +00003852 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003853 if (Result.isNull())
3854 return QualType();
3855
3856 // Silently suppress qualifiers if the result type can't be qualified.
3857 // FIXME: this is the right thing for template instantiation, but
3858 // probably not for other clients.
3859 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003860 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003861
John McCall31168b02011-06-15 23:02:42 +00003862 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003863 // resulting type.
3864 if (Quals.hasObjCLifetime()) {
3865 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3866 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003867 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003868 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003869 // A lifetime qualifier applied to a substituted template parameter
3870 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003871 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003872 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003873 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3874 QualType Replacement = SubstTypeParam->getReplacementType();
3875 Qualifiers Qs = Replacement.getQualifiers();
3876 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003877 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003878 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3879 Qs);
3880 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003881 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003882 Replacement);
3883 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003884 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3885 // 'auto' types behave the same way as template parameters.
3886 QualType Deduced = AutoTy->getDeducedType();
3887 Qualifiers Qs = Deduced.getQualifiers();
3888 Qs.removeObjCLifetime();
3889 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3890 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003891 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3892 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003893 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003894 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003895 // Otherwise, complain about the addition of a qualifier to an
3896 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003897 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003898 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003899 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003900
Douglas Gregore46db902011-06-17 22:11:49 +00003901 Quals.removeObjCLifetime();
3902 }
3903 }
3904 }
John McCallcb0f89a2010-06-05 06:41:15 +00003905 if (!Quals.empty()) {
3906 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003907 // BuildQualifiedType might not add qualifiers if they are invalid.
3908 if (Result.hasLocalQualifiers())
3909 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003910 // No location information to preserve.
3911 }
John McCall550e0c22009-10-21 00:40:46 +00003912
3913 return Result;
3914}
3915
Douglas Gregor14454802011-02-25 02:25:35 +00003916template<typename Derived>
3917TypeLoc
3918TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3919 QualType ObjectType,
3920 NamedDecl *UnqualLookup,
3921 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003922 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003923 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003924
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003925 TypeSourceInfo *TSI =
3926 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3927 if (TSI)
3928 return TSI->getTypeLoc();
3929 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003930}
3931
Douglas Gregor579c15f2011-03-02 18:32:08 +00003932template<typename Derived>
3933TypeSourceInfo *
3934TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3935 QualType ObjectType,
3936 NamedDecl *UnqualLookup,
3937 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003938 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003939 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003940
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003941 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3942 UnqualLookup, SS);
3943}
3944
3945template <typename Derived>
3946TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3947 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3948 CXXScopeSpec &SS) {
3949 QualType T = TL.getType();
3950 assert(!getDerived().AlreadyTransformed(T));
3951
Douglas Gregor579c15f2011-03-02 18:32:08 +00003952 TypeLocBuilder TLB;
3953 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003954
Douglas Gregor579c15f2011-03-02 18:32:08 +00003955 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003956 TemplateSpecializationTypeLoc SpecTL =
3957 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
Douglas Gregor579c15f2011-03-02 18:32:08 +00003959 TemplateName Template
3960 = getDerived().TransformTemplateName(SS,
3961 SpecTL.getTypePtr()->getTemplateName(),
3962 SpecTL.getTemplateNameLoc(),
3963 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003964 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003965 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
3967 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003968 Template);
3969 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003970 DependentTemplateSpecializationTypeLoc SpecTL =
3971 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003972
Douglas Gregor579c15f2011-03-02 18:32:08 +00003973 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003974 = getDerived().RebuildTemplateName(SS,
3975 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003976 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003977 ObjectType, UnqualLookup);
3978 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003979 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003980
3981 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003982 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003983 Template,
3984 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003985 } else {
3986 // Nothing special needs to be done for these.
3987 Result = getDerived().TransformType(TLB, TL);
3988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003989
3990 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003991 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003992
Douglas Gregor579c15f2011-03-02 18:32:08 +00003993 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3994}
3995
John McCall550e0c22009-10-21 00:40:46 +00003996template <class TyLoc> static inline
3997QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3998 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3999 NewT.setNameLoc(T.getNameLoc());
4000 return T.getType();
4001}
4002
John McCall550e0c22009-10-21 00:40:46 +00004003template<typename Derived>
4004QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004005 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004006 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4007 NewT.setBuiltinLoc(T.getBuiltinLoc());
4008 if (T.needsExtraLocalData())
4009 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4010 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011}
Mike Stump11289f42009-09-09 15:08:12 +00004012
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004014QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004015 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004016 // FIXME: recurse?
4017 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
Reid Kleckner0503a872013-12-05 01:23:43 +00004020template <typename Derived>
4021QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4022 AdjustedTypeLoc TL) {
4023 // Adjustments applied during transformation are handled elsewhere.
4024 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4025}
4026
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004028QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4029 DecayedTypeLoc TL) {
4030 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4031 if (OriginalType.isNull())
4032 return QualType();
4033
4034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() ||
4036 OriginalType != TL.getOriginalLoc().getType())
4037 Result = SemaRef.Context.getDecayedType(OriginalType);
4038 TLB.push<DecayedTypeLoc>(Result);
4039 // Nothing to set for DecayedTypeLoc.
4040 return Result;
4041}
4042
4043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004044QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004045 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004046 QualType PointeeType
4047 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004048 if (PointeeType.isNull())
4049 return QualType();
4050
4051 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004052 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004053 // A dependent pointer type 'T *' has is being transformed such
4054 // that an Objective-C class type is being replaced for 'T'. The
4055 // resulting pointer type is an ObjCObjectPointerType, not a
4056 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004057 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004058
John McCall8b07ec22010-05-15 11:32:37 +00004059 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4060 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004061 return Result;
4062 }
John McCall31f82722010-11-12 08:19:04 +00004063
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004064 if (getDerived().AlwaysRebuild() ||
4065 PointeeType != TL.getPointeeLoc().getType()) {
4066 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4067 if (Result.isNull())
4068 return QualType();
4069 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004070
John McCall31168b02011-06-15 23:02:42 +00004071 // Objective-C ARC can add lifetime qualifiers to the type that we're
4072 // pointing to.
4073 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004075 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4076 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004077 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004078}
Mike Stump11289f42009-09-09 15:08:12 +00004079
4080template<typename Derived>
4081QualType
John McCall550e0c22009-10-21 00:40:46 +00004082TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004083 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004084 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004085 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4086 if (PointeeType.isNull())
4087 return QualType();
4088
4089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
4091 PointeeType != TL.getPointeeLoc().getType()) {
4092 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004093 TL.getSigilLoc());
4094 if (Result.isNull())
4095 return QualType();
4096 }
4097
Douglas Gregor049211a2010-04-22 16:50:51 +00004098 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004099 NewT.setSigilLoc(TL.getSigilLoc());
4100 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004101}
4102
John McCall70dd5f62009-10-30 00:06:24 +00004103/// Transforms a reference type. Note that somewhat paradoxically we
4104/// don't care whether the type itself is an l-value type or an r-value
4105/// type; we only care if the type was *written* as an l-value type
4106/// or an r-value type.
4107template<typename Derived>
4108QualType
4109TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004110 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004111 const ReferenceType *T = TL.getTypePtr();
4112
4113 // Note that this works with the pointee-as-written.
4114 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4115 if (PointeeType.isNull())
4116 return QualType();
4117
4118 QualType Result = TL.getType();
4119 if (getDerived().AlwaysRebuild() ||
4120 PointeeType != T->getPointeeTypeAsWritten()) {
4121 Result = getDerived().RebuildReferenceType(PointeeType,
4122 T->isSpelledAsLValue(),
4123 TL.getSigilLoc());
4124 if (Result.isNull())
4125 return QualType();
4126 }
4127
John McCall31168b02011-06-15 23:02:42 +00004128 // Objective-C ARC can add lifetime qualifiers to the type that we're
4129 // referring to.
4130 TLB.TypeWasModifiedSafely(
4131 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4132
John McCall70dd5f62009-10-30 00:06:24 +00004133 // r-value references can be rebuilt as l-value references.
4134 ReferenceTypeLoc NewTL;
4135 if (isa<LValueReferenceType>(Result))
4136 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4137 else
4138 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4139 NewTL.setSigilLoc(TL.getSigilLoc());
4140
4141 return Result;
4142}
4143
Mike Stump11289f42009-09-09 15:08:12 +00004144template<typename Derived>
4145QualType
John McCall550e0c22009-10-21 00:40:46 +00004146TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004147 LValueReferenceTypeLoc TL) {
4148 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
4150
Mike Stump11289f42009-09-09 15:08:12 +00004151template<typename Derived>
4152QualType
John McCall550e0c22009-10-21 00:40:46 +00004153TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 RValueReferenceTypeLoc TL) {
4155 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004156}
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004159QualType
John McCall550e0c22009-10-21 00:40:46 +00004160TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004162 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004163 if (PointeeType.isNull())
4164 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004165
Abramo Bagnara509357842011-03-05 14:42:21 +00004166 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004167 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004168 if (OldClsTInfo) {
4169 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4170 if (!NewClsTInfo)
4171 return QualType();
4172 }
4173
4174 const MemberPointerType *T = TL.getTypePtr();
4175 QualType OldClsType = QualType(T->getClass(), 0);
4176 QualType NewClsType;
4177 if (NewClsTInfo)
4178 NewClsType = NewClsTInfo->getType();
4179 else {
4180 NewClsType = getDerived().TransformType(OldClsType);
4181 if (NewClsType.isNull())
4182 return QualType();
4183 }
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 QualType Result = TL.getType();
4186 if (getDerived().AlwaysRebuild() ||
4187 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004188 NewClsType != OldClsType) {
4189 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004190 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004191 if (Result.isNull())
4192 return QualType();
4193 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004194
Reid Kleckner0503a872013-12-05 01:23:43 +00004195 // If we had to adjust the pointee type when building a member pointer, make
4196 // sure to push TypeLoc info for it.
4197 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4198 if (MPT && PointeeType != MPT->getPointeeType()) {
4199 assert(isa<AdjustedType>(MPT->getPointeeType()));
4200 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4201 }
4202
John McCall550e0c22009-10-21 00:40:46 +00004203 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4204 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004205 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004206
4207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208}
4209
Mike Stump11289f42009-09-09 15:08:12 +00004210template<typename Derived>
4211QualType
John McCall550e0c22009-10-21 00:40:46 +00004212TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004213 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004214 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004215 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004216 if (ElementType.isNull())
4217 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004218
John McCall550e0c22009-10-21 00:40:46 +00004219 QualType Result = TL.getType();
4220 if (getDerived().AlwaysRebuild() ||
4221 ElementType != T->getElementType()) {
4222 Result = getDerived().RebuildConstantArrayType(ElementType,
4223 T->getSizeModifier(),
4224 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004225 T->getIndexTypeCVRQualifiers(),
4226 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004227 if (Result.isNull())
4228 return QualType();
4229 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004230
4231 // We might have either a ConstantArrayType or a VariableArrayType now:
4232 // a ConstantArrayType is allowed to have an element type which is a
4233 // VariableArrayType if the type is dependent. Fortunately, all array
4234 // types have the same location layout.
4235 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004236 NewTL.setLBracketLoc(TL.getLBracketLoc());
4237 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004238
John McCall550e0c22009-10-21 00:40:46 +00004239 Expr *Size = TL.getSizeExpr();
4240 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004241 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4242 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004243 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4244 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004245 }
4246 NewTL.setSizeExpr(Size);
4247
4248 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004249}
Mike Stump11289f42009-09-09 15:08:12 +00004250
Douglas Gregord6ff3322009-08-04 16:50:30 +00004251template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004253 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004254 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004255 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004256 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257 if (ElementType.isNull())
4258 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004259
John McCall550e0c22009-10-21 00:40:46 +00004260 QualType Result = TL.getType();
4261 if (getDerived().AlwaysRebuild() ||
4262 ElementType != T->getElementType()) {
4263 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004264 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004265 T->getIndexTypeCVRQualifiers(),
4266 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004267 if (Result.isNull())
4268 return QualType();
4269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4272 NewTL.setLBracketLoc(TL.getLBracketLoc());
4273 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004274 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004275
4276 return Result;
4277}
4278
4279template<typename Derived>
4280QualType
4281TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004282 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004283 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004284 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4285 if (ElementType.isNull())
4286 return QualType();
4287
John McCalldadc5752010-08-24 06:29:42 +00004288 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004289 = getDerived().TransformExpr(T->getSizeExpr());
4290 if (SizeResult.isInvalid())
4291 return QualType();
4292
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004293 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004294
4295 QualType Result = TL.getType();
4296 if (getDerived().AlwaysRebuild() ||
4297 ElementType != T->getElementType() ||
4298 Size != T->getSizeExpr()) {
4299 Result = getDerived().RebuildVariableArrayType(ElementType,
4300 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004301 Size,
John McCall550e0c22009-10-21 00:40:46 +00004302 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004303 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004304 if (Result.isNull())
4305 return QualType();
4306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Serge Pavlov774c6d02014-02-06 03:49:11 +00004308 // We might have constant size array now, but fortunately it has the same
4309 // location layout.
4310 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004311 NewTL.setLBracketLoc(TL.getLBracketLoc());
4312 NewTL.setRBracketLoc(TL.getRBracketLoc());
4313 NewTL.setSizeExpr(Size);
4314
4315 return Result;
4316}
4317
4318template<typename Derived>
4319QualType
4320TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004321 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004322 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004323 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4324 if (ElementType.isNull())
4325 return QualType();
4326
Richard Smith764d2fe2011-12-20 02:08:33 +00004327 // Array bounds are constant expressions.
4328 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4329 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004330
John McCall33ddac02011-01-19 10:06:00 +00004331 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4332 Expr *origSize = TL.getSizeExpr();
4333 if (!origSize) origSize = T->getSizeExpr();
4334
4335 ExprResult sizeResult
4336 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004337 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004338 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004339 return QualType();
4340
John McCall33ddac02011-01-19 10:06:00 +00004341 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004342
4343 QualType Result = TL.getType();
4344 if (getDerived().AlwaysRebuild() ||
4345 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004346 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004347 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4348 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004349 size,
John McCall550e0c22009-10-21 00:40:46 +00004350 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004351 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004352 if (Result.isNull())
4353 return QualType();
4354 }
John McCall550e0c22009-10-21 00:40:46 +00004355
4356 // We might have any sort of array type now, but fortunately they
4357 // all have the same location layout.
4358 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4359 NewTL.setLBracketLoc(TL.getLBracketLoc());
4360 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004361 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004362
4363 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004364}
Mike Stump11289f42009-09-09 15:08:12 +00004365
4366template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004367QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004368 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004369 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004370 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004371
4372 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004373 QualType ElementType = getDerived().TransformType(T->getElementType());
4374 if (ElementType.isNull())
4375 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004376
Richard Smith764d2fe2011-12-20 02:08:33 +00004377 // Vector sizes are constant expressions.
4378 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4379 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004380
John McCalldadc5752010-08-24 06:29:42 +00004381 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004382 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004383 if (Size.isInvalid())
4384 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004385
John McCall550e0c22009-10-21 00:40:46 +00004386 QualType Result = TL.getType();
4387 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004388 ElementType != T->getElementType() ||
4389 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004390 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004391 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004392 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004393 if (Result.isNull())
4394 return QualType();
4395 }
John McCall550e0c22009-10-21 00:40:46 +00004396
4397 // Result might be dependent or not.
4398 if (isa<DependentSizedExtVectorType>(Result)) {
4399 DependentSizedExtVectorTypeLoc NewTL
4400 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4401 NewTL.setNameLoc(TL.getNameLoc());
4402 } else {
4403 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4404 NewTL.setNameLoc(TL.getNameLoc());
4405 }
4406
4407 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004408}
Mike Stump11289f42009-09-09 15:08:12 +00004409
4410template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004411QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004412 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004413 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004414 QualType ElementType = getDerived().TransformType(T->getElementType());
4415 if (ElementType.isNull())
4416 return QualType();
4417
John McCall550e0c22009-10-21 00:40:46 +00004418 QualType Result = TL.getType();
4419 if (getDerived().AlwaysRebuild() ||
4420 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004421 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004422 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004423 if (Result.isNull())
4424 return QualType();
4425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
John McCall550e0c22009-10-21 00:40:46 +00004427 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4428 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004429
John McCall550e0c22009-10-21 00:40:46 +00004430 return Result;
4431}
4432
4433template<typename Derived>
4434QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004435 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004436 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004437 QualType ElementType = getDerived().TransformType(T->getElementType());
4438 if (ElementType.isNull())
4439 return QualType();
4440
4441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 ElementType != T->getElementType()) {
4444 Result = getDerived().RebuildExtVectorType(ElementType,
4445 T->getNumElements(),
4446 /*FIXME*/ SourceLocation());
4447 if (Result.isNull())
4448 return QualType();
4449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004450
John McCall550e0c22009-10-21 00:40:46 +00004451 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4452 NewTL.setNameLoc(TL.getNameLoc());
4453
4454 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004455}
Mike Stump11289f42009-09-09 15:08:12 +00004456
David Blaikie05785d12013-02-20 22:23:23 +00004457template <typename Derived>
4458ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4459 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4460 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004461 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004462 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004463
Douglas Gregor715e4612011-01-14 22:40:04 +00004464 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004465 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004466 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004467 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004468 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004469
Douglas Gregor715e4612011-01-14 22:40:04 +00004470 TypeLocBuilder TLB;
4471 TypeLoc NewTL = OldDI->getTypeLoc();
4472 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004473
4474 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004475 OldExpansionTL.getPatternLoc());
4476 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004477 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004478
4479 Result = RebuildPackExpansionType(Result,
4480 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004481 OldExpansionTL.getEllipsisLoc(),
4482 NumExpansions);
4483 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004484 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004485
Douglas Gregor715e4612011-01-14 22:40:04 +00004486 PackExpansionTypeLoc NewExpansionTL
4487 = TLB.push<PackExpansionTypeLoc>(Result);
4488 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4489 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4490 } else
4491 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004492 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004493 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004494
John McCall8fb0d9d2011-05-01 22:35:37 +00004495 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004496 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004497
4498 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4499 OldParm->getDeclContext(),
4500 OldParm->getInnerLocStart(),
4501 OldParm->getLocation(),
4502 OldParm->getIdentifier(),
4503 NewDI->getType(),
4504 NewDI,
4505 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004506 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004507 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4508 OldParm->getFunctionScopeIndex() + indexAdjustment);
4509 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004510}
4511
4512template<typename Derived>
4513bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004514 TransformFunctionTypeParams(SourceLocation Loc,
4515 ParmVarDecl **Params, unsigned NumParams,
4516 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004517 SmallVectorImpl<QualType> &OutParamTypes,
4518 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004519 int indexAdjustment = 0;
4520
Douglas Gregordd472162011-01-07 00:20:55 +00004521 for (unsigned i = 0; i != NumParams; ++i) {
4522 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004523 assert(OldParm->getFunctionScopeIndex() == i);
4524
David Blaikie05785d12013-02-20 22:23:23 +00004525 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004526 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004527 if (OldParm->isParameterPack()) {
4528 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004529 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004530
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004532 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004533 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004534 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4535 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004536 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4537
Douglas Gregor5499af42011-01-05 23:12:31 +00004538 // Determine whether we should expand the parameter packs.
4539 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004540 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004541 Optional<unsigned> OrigNumExpansions =
4542 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004543 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004544 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4545 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004546 Unexpanded,
4547 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004548 RetainExpansion,
4549 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004550 return true;
4551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004552
Douglas Gregor5499af42011-01-05 23:12:31 +00004553 if (ShouldExpand) {
4554 // Expand the function parameter pack into multiple, separate
4555 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004556 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004557 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004558 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004559 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004560 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004561 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004562 OrigNumExpansions,
4563 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004564 if (!NewParm)
4565 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004566
Douglas Gregordd472162011-01-07 00:20:55 +00004567 OutParamTypes.push_back(NewParm->getType());
4568 if (PVars)
4569 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004570 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004571
4572 // If we're supposed to retain a pack expansion, do so by temporarily
4573 // forgetting the partially-substituted parameter pack.
4574 if (RetainExpansion) {
4575 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004576 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004577 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004578 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004579 OrigNumExpansions,
4580 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004581 if (!NewParm)
4582 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004583
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004584 OutParamTypes.push_back(NewParm->getType());
4585 if (PVars)
4586 PVars->push_back(NewParm);
4587 }
4588
John McCall8fb0d9d2011-05-01 22:35:37 +00004589 // The next parameter should have the same adjustment as the
4590 // last thing we pushed, but we post-incremented indexAdjustment
4591 // on every push. Also, if we push nothing, the adjustment should
4592 // go down by one.
4593 indexAdjustment--;
4594
Douglas Gregor5499af42011-01-05 23:12:31 +00004595 // We're done with the pack expansion.
4596 continue;
4597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004598
4599 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004600 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4602 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004603 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004604 NumExpansions,
4605 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004606 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004607 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004608 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004609 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004610
John McCall58f10c32010-03-11 09:03:00 +00004611 if (!NewParm)
4612 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004613
Douglas Gregordd472162011-01-07 00:20:55 +00004614 OutParamTypes.push_back(NewParm->getType());
4615 if (PVars)
4616 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004617 continue;
4618 }
John McCall58f10c32010-03-11 09:03:00 +00004619
4620 // Deal with the possibility that we don't have a parameter
4621 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004622 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004623 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004624 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004625 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004626 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004627 = dyn_cast<PackExpansionType>(OldType)) {
4628 // We have a function parameter pack that may need to be expanded.
4629 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004630 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004631 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Douglas Gregor5499af42011-01-05 23:12:31 +00004633 // Determine whether we should expand the parameter packs.
4634 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004635 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004636 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004637 Unexpanded,
4638 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004639 RetainExpansion,
4640 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004641 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004643
Douglas Gregor5499af42011-01-05 23:12:31 +00004644 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004645 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004646 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004647 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004648 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4649 QualType NewType = getDerived().TransformType(Pattern);
4650 if (NewType.isNull())
4651 return true;
John McCall58f10c32010-03-11 09:03:00 +00004652
Douglas Gregordd472162011-01-07 00:20:55 +00004653 OutParamTypes.push_back(NewType);
4654 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004655 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004657
Douglas Gregor5499af42011-01-05 23:12:31 +00004658 // We're done with the pack expansion.
4659 continue;
4660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004661
Douglas Gregor48d24112011-01-10 20:53:55 +00004662 // If we're supposed to retain a pack expansion, do so by temporarily
4663 // forgetting the partially-substituted parameter pack.
4664 if (RetainExpansion) {
4665 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4666 QualType NewType = getDerived().TransformType(Pattern);
4667 if (NewType.isNull())
4668 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004669
Douglas Gregor48d24112011-01-10 20:53:55 +00004670 OutParamTypes.push_back(NewType);
4671 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004672 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004673 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004674
Chad Rosier1dcde962012-08-08 18:46:20 +00004675 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004676 // expansion.
4677 OldType = Expansion->getPattern();
4678 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004679 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4680 NewType = getDerived().TransformType(OldType);
4681 } else {
4682 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004683 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004684
Douglas Gregor5499af42011-01-05 23:12:31 +00004685 if (NewType.isNull())
4686 return true;
4687
4688 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004689 NewType = getSema().Context.getPackExpansionType(NewType,
4690 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004691
Douglas Gregordd472162011-01-07 00:20:55 +00004692 OutParamTypes.push_back(NewType);
4693 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004694 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004695 }
4696
John McCall8fb0d9d2011-05-01 22:35:37 +00004697#ifndef NDEBUG
4698 if (PVars) {
4699 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4700 if (ParmVarDecl *parm = (*PVars)[i])
4701 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004702 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004703#endif
4704
4705 return false;
4706}
John McCall58f10c32010-03-11 09:03:00 +00004707
4708template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004709QualType
John McCall550e0c22009-10-21 00:40:46 +00004710TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004711 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004712 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004713 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004714 return getDerived().TransformFunctionProtoType(
4715 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004716 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4717 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4718 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004719 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004720}
4721
Richard Smith2e321552014-11-12 02:00:47 +00004722template<typename Derived> template<typename Fn>
4723QualType TreeTransform<Derived>::TransformFunctionProtoType(
4724 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4725 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004726 // Transform the parameters and return type.
4727 //
Richard Smithf623c962012-04-17 00:58:00 +00004728 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004729 // When the function has a trailing return type, we instantiate the
4730 // parameters before the return type, since the return type can then refer
4731 // to the parameters themselves (via decltype, sizeof, etc.).
4732 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004733 SmallVector<QualType, 4> ParamTypes;
4734 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004735 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004736
Douglas Gregor7fb25412010-10-01 18:44:50 +00004737 QualType ResultType;
4738
Richard Smith1226c602012-08-14 22:51:13 +00004739 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004740 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004741 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004742 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004743 return QualType();
4744
Douglas Gregor3024f072012-04-16 07:05:22 +00004745 {
4746 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004747 // If a declaration declares a member function or member function
4748 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004749 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004750 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004751 // declarator.
4752 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004753
Alp Toker42a16a62014-01-25 23:51:36 +00004754 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004755 if (ResultType.isNull())
4756 return QualType();
4757 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004758 }
4759 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004760 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004761 if (ResultType.isNull())
4762 return QualType();
4763
Alp Toker9cacbab2014-01-20 20:26:09 +00004764 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004765 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004766 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004767 return QualType();
4768 }
4769
Richard Smith2e321552014-11-12 02:00:47 +00004770 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4771
4772 bool EPIChanged = false;
4773 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4774 return QualType();
4775
4776 // FIXME: Need to transform ConsumedParameters for variadic template
4777 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004778
John McCall550e0c22009-10-21 00:40:46 +00004779 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004780 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004781 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004782 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004783 if (Result.isNull())
4784 return QualType();
4785 }
Mike Stump11289f42009-09-09 15:08:12 +00004786
John McCall550e0c22009-10-21 00:40:46 +00004787 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004788 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004789 NewTL.setLParenLoc(TL.getLParenLoc());
4790 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004791 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004792 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4793 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004794
4795 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004796}
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004799bool TreeTransform<Derived>::TransformExceptionSpec(
4800 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4801 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4802 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4803
4804 // Instantiate a dynamic noexcept expression, if any.
4805 if (ESI.Type == EST_ComputedNoexcept) {
4806 EnterExpressionEvaluationContext Unevaluated(getSema(),
4807 Sema::ConstantEvaluated);
4808 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4809 if (NoexceptExpr.isInvalid())
4810 return true;
4811
4812 NoexceptExpr = getSema().CheckBooleanCondition(
4813 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4814 if (NoexceptExpr.isInvalid())
4815 return true;
4816
4817 if (!NoexceptExpr.get()->isValueDependent()) {
4818 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4819 NoexceptExpr.get(), nullptr,
4820 diag::err_noexcept_needs_constant_expression,
4821 /*AllowFold*/false);
4822 if (NoexceptExpr.isInvalid())
4823 return true;
4824 }
4825
4826 if (ESI.NoexceptExpr != NoexceptExpr.get())
4827 Changed = true;
4828 ESI.NoexceptExpr = NoexceptExpr.get();
4829 }
4830
4831 if (ESI.Type != EST_Dynamic)
4832 return false;
4833
4834 // Instantiate a dynamic exception specification's type.
4835 for (QualType T : ESI.Exceptions) {
4836 if (const PackExpansionType *PackExpansion =
4837 T->getAs<PackExpansionType>()) {
4838 Changed = true;
4839
4840 // We have a pack expansion. Instantiate it.
4841 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4842 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4843 Unexpanded);
4844 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4845
4846 // Determine whether the set of unexpanded parameter packs can and
4847 // should
4848 // be expanded.
4849 bool Expand = false;
4850 bool RetainExpansion = false;
4851 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4852 // FIXME: Track the location of the ellipsis (and track source location
4853 // information for the types in the exception specification in general).
4854 if (getDerived().TryExpandParameterPacks(
4855 Loc, SourceRange(), Unexpanded, Expand,
4856 RetainExpansion, NumExpansions))
4857 return true;
4858
4859 if (!Expand) {
4860 // We can't expand this pack expansion into separate arguments yet;
4861 // just substitute into the pattern and create a new pack expansion
4862 // type.
4863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4864 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4865 if (U.isNull())
4866 return true;
4867
4868 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4869 Exceptions.push_back(U);
4870 continue;
4871 }
4872
4873 // Substitute into the pack expansion pattern for each slice of the
4874 // pack.
4875 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4877
4878 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4879 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4880 return true;
4881
4882 Exceptions.push_back(U);
4883 }
4884 } else {
4885 QualType U = getDerived().TransformType(T);
4886 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4887 return true;
4888 if (T != U)
4889 Changed = true;
4890
4891 Exceptions.push_back(U);
4892 }
4893 }
4894
4895 ESI.Exceptions = Exceptions;
4896 return false;
4897}
4898
4899template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004901 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004902 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004903 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004904 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004905 if (ResultType.isNull())
4906 return QualType();
4907
4908 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004909 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004910 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4911
4912 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004913 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004914 NewTL.setLParenLoc(TL.getLParenLoc());
4915 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004916 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004917
4918 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004919}
Mike Stump11289f42009-09-09 15:08:12 +00004920
John McCallb96ec562009-12-04 22:46:56 +00004921template<typename Derived> QualType
4922TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004923 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004924 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004925 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004926 if (!D)
4927 return QualType();
4928
4929 QualType Result = TL.getType();
4930 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4931 Result = getDerived().RebuildUnresolvedUsingType(D);
4932 if (Result.isNull())
4933 return QualType();
4934 }
4935
4936 // We might get an arbitrary type spec type back. We should at
4937 // least always get a type spec type, though.
4938 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4939 NewTL.setNameLoc(TL.getNameLoc());
4940
4941 return Result;
4942}
4943
Douglas Gregord6ff3322009-08-04 16:50:30 +00004944template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004945QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004946 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004947 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004948 TypedefNameDecl *Typedef
4949 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4950 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004951 if (!Typedef)
4952 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004953
John McCall550e0c22009-10-21 00:40:46 +00004954 QualType Result = TL.getType();
4955 if (getDerived().AlwaysRebuild() ||
4956 Typedef != T->getDecl()) {
4957 Result = getDerived().RebuildTypedefType(Typedef);
4958 if (Result.isNull())
4959 return QualType();
4960 }
Mike Stump11289f42009-09-09 15:08:12 +00004961
John McCall550e0c22009-10-21 00:40:46 +00004962 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4963 NewTL.setNameLoc(TL.getNameLoc());
4964
4965 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004966}
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregord6ff3322009-08-04 16:50:30 +00004968template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004969QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004970 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004971 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004972 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4973 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCalldadc5752010-08-24 06:29:42 +00004975 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004976 if (E.isInvalid())
4977 return QualType();
4978
Eli Friedmane4f22df2012-02-29 04:03:55 +00004979 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4980 if (E.isInvalid())
4981 return QualType();
4982
John McCall550e0c22009-10-21 00:40:46 +00004983 QualType Result = TL.getType();
4984 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004985 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004986 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004987 if (Result.isNull())
4988 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004989 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004990 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004991
John McCall550e0c22009-10-21 00:40:46 +00004992 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004993 NewTL.setTypeofLoc(TL.getTypeofLoc());
4994 NewTL.setLParenLoc(TL.getLParenLoc());
4995 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004996
4997 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998}
Mike Stump11289f42009-09-09 15:08:12 +00004999
5000template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005001QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005002 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005003 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5004 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5005 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005006 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005007
John McCall550e0c22009-10-21 00:40:46 +00005008 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005009 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5010 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005011 if (Result.isNull())
5012 return QualType();
5013 }
Mike Stump11289f42009-09-09 15:08:12 +00005014
John McCall550e0c22009-10-21 00:40:46 +00005015 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005016 NewTL.setTypeofLoc(TL.getTypeofLoc());
5017 NewTL.setLParenLoc(TL.getLParenLoc());
5018 NewTL.setRParenLoc(TL.getRParenLoc());
5019 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005020
5021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022}
Mike Stump11289f42009-09-09 15:08:12 +00005023
5024template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005025QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005026 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005027 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005028
Douglas Gregore922c772009-08-04 22:27:00 +00005029 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005030 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5031 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005032
John McCalldadc5752010-08-24 06:29:42 +00005033 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005034 if (E.isInvalid())
5035 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005036
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005037 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005038 if (E.isInvalid())
5039 return QualType();
5040
John McCall550e0c22009-10-21 00:40:46 +00005041 QualType Result = TL.getType();
5042 if (getDerived().AlwaysRebuild() ||
5043 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005044 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005045 if (Result.isNull())
5046 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005047 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005048 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005049
John McCall550e0c22009-10-21 00:40:46 +00005050 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5051 NewTL.setNameLoc(TL.getNameLoc());
5052
5053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005054}
5055
5056template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005057QualType TreeTransform<Derived>::TransformUnaryTransformType(
5058 TypeLocBuilder &TLB,
5059 UnaryTransformTypeLoc TL) {
5060 QualType Result = TL.getType();
5061 if (Result->isDependentType()) {
5062 const UnaryTransformType *T = TL.getTypePtr();
5063 QualType NewBase =
5064 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5065 Result = getDerived().RebuildUnaryTransformType(NewBase,
5066 T->getUTTKind(),
5067 TL.getKWLoc());
5068 if (Result.isNull())
5069 return QualType();
5070 }
5071
5072 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5073 NewTL.setKWLoc(TL.getKWLoc());
5074 NewTL.setParensRange(TL.getParensRange());
5075 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5076 return Result;
5077}
5078
5079template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005080QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5081 AutoTypeLoc TL) {
5082 const AutoType *T = TL.getTypePtr();
5083 QualType OldDeduced = T->getDeducedType();
5084 QualType NewDeduced;
5085 if (!OldDeduced.isNull()) {
5086 NewDeduced = getDerived().TransformType(OldDeduced);
5087 if (NewDeduced.isNull())
5088 return QualType();
5089 }
5090
5091 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005092 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5093 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005094 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005095 if (Result.isNull())
5096 return QualType();
5097 }
5098
5099 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5100 NewTL.setNameLoc(TL.getNameLoc());
5101
5102 return Result;
5103}
5104
5105template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005106QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005107 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005108 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005110 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5111 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112 if (!Record)
5113 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005114
John McCall550e0c22009-10-21 00:40:46 +00005115 QualType Result = TL.getType();
5116 if (getDerived().AlwaysRebuild() ||
5117 Record != T->getDecl()) {
5118 Result = getDerived().RebuildRecordType(Record);
5119 if (Result.isNull())
5120 return QualType();
5121 }
Mike Stump11289f42009-09-09 15:08:12 +00005122
John McCall550e0c22009-10-21 00:40:46 +00005123 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5124 NewTL.setNameLoc(TL.getNameLoc());
5125
5126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127}
Mike Stump11289f42009-09-09 15:08:12 +00005128
5129template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005130QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005132 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005133 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005134 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5135 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005136 if (!Enum)
5137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005138
John McCall550e0c22009-10-21 00:40:46 +00005139 QualType Result = TL.getType();
5140 if (getDerived().AlwaysRebuild() ||
5141 Enum != T->getDecl()) {
5142 Result = getDerived().RebuildEnumType(Enum);
5143 if (Result.isNull())
5144 return QualType();
5145 }
Mike Stump11289f42009-09-09 15:08:12 +00005146
John McCall550e0c22009-10-21 00:40:46 +00005147 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5148 NewTL.setNameLoc(TL.getNameLoc());
5149
5150 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005151}
John McCallfcc33b02009-09-05 00:15:47 +00005152
John McCalle78aac42010-03-10 03:28:59 +00005153template<typename Derived>
5154QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5155 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005156 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005157 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5158 TL.getTypePtr()->getDecl());
5159 if (!D) return QualType();
5160
5161 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5162 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5163 return T;
5164}
5165
Douglas Gregord6ff3322009-08-04 16:50:30 +00005166template<typename Derived>
5167QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005168 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005169 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005170 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171}
5172
Mike Stump11289f42009-09-09 15:08:12 +00005173template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005174QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005175 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005176 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005177 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005178
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005179 // Substitute into the replacement type, which itself might involve something
5180 // that needs to be transformed. This only tends to occur with default
5181 // template arguments of template template parameters.
5182 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5183 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5184 if (Replacement.isNull())
5185 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005186
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005187 // Always canonicalize the replacement type.
5188 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5189 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005190 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005191 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005192
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005193 // Propagate type-source information.
5194 SubstTemplateTypeParmTypeLoc NewTL
5195 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5196 NewTL.setNameLoc(TL.getNameLoc());
5197 return Result;
5198
John McCallcebee162009-10-18 09:09:24 +00005199}
5200
5201template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005202QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5203 TypeLocBuilder &TLB,
5204 SubstTemplateTypeParmPackTypeLoc TL) {
5205 return TransformTypeSpecType(TLB, TL);
5206}
5207
5208template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005209QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005210 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005211 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005212 const TemplateSpecializationType *T = TL.getTypePtr();
5213
Douglas Gregordf846d12011-03-02 18:46:51 +00005214 // The nested-name-specifier never matters in a TemplateSpecializationType,
5215 // because we can't have a dependent nested-name-specifier anyway.
5216 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005217 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005218 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5219 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005220 if (Template.isNull())
5221 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005222
John McCall31f82722010-11-12 08:19:04 +00005223 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5224}
5225
Eli Friedman0dfb8892011-10-06 23:00:33 +00005226template<typename Derived>
5227QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5228 AtomicTypeLoc TL) {
5229 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5230 if (ValueType.isNull())
5231 return QualType();
5232
5233 QualType Result = TL.getType();
5234 if (getDerived().AlwaysRebuild() ||
5235 ValueType != TL.getValueLoc().getType()) {
5236 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5237 if (Result.isNull())
5238 return QualType();
5239 }
5240
5241 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5242 NewTL.setKWLoc(TL.getKWLoc());
5243 NewTL.setLParenLoc(TL.getLParenLoc());
5244 NewTL.setRParenLoc(TL.getRParenLoc());
5245
5246 return Result;
5247}
5248
Chad Rosier1dcde962012-08-08 18:46:20 +00005249 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005250 /// container that provides a \c getArgLoc() member function.
5251 ///
5252 /// This iterator is intended to be used with the iterator form of
5253 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5254 template<typename ArgLocContainer>
5255 class TemplateArgumentLocContainerIterator {
5256 ArgLocContainer *Container;
5257 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005258
Douglas Gregorfe921a72010-12-20 23:36:19 +00005259 public:
5260 typedef TemplateArgumentLoc value_type;
5261 typedef TemplateArgumentLoc reference;
5262 typedef int difference_type;
5263 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregorfe921a72010-12-20 23:36:19 +00005265 class pointer {
5266 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005267
Douglas Gregorfe921a72010-12-20 23:36:19 +00005268 public:
5269 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005270
Douglas Gregorfe921a72010-12-20 23:36:19 +00005271 const TemplateArgumentLoc *operator->() const {
5272 return &Arg;
5273 }
5274 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005275
5276
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005277 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005278
Douglas Gregorfe921a72010-12-20 23:36:19 +00005279 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5280 unsigned Index)
5281 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregorfe921a72010-12-20 23:36:19 +00005283 TemplateArgumentLocContainerIterator &operator++() {
5284 ++Index;
5285 return *this;
5286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
Douglas Gregorfe921a72010-12-20 23:36:19 +00005288 TemplateArgumentLocContainerIterator operator++(int) {
5289 TemplateArgumentLocContainerIterator Old(*this);
5290 ++(*this);
5291 return Old;
5292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005293
Douglas Gregorfe921a72010-12-20 23:36:19 +00005294 TemplateArgumentLoc operator*() const {
5295 return Container->getArgLoc(Index);
5296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005297
Douglas Gregorfe921a72010-12-20 23:36:19 +00005298 pointer operator->() const {
5299 return pointer(Container->getArgLoc(Index));
5300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005301
Douglas Gregorfe921a72010-12-20 23:36:19 +00005302 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005303 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005304 return X.Container == Y.Container && X.Index == Y.Index;
5305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005306
Douglas Gregorfe921a72010-12-20 23:36:19 +00005307 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005308 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005309 return !(X == Y);
5310 }
5311 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
5313
John McCall31f82722010-11-12 08:19:04 +00005314template <typename Derived>
5315QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5316 TypeLocBuilder &TLB,
5317 TemplateSpecializationTypeLoc TL,
5318 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005319 TemplateArgumentListInfo NewTemplateArgs;
5320 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5321 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005322 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5323 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005324 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005325 ArgIterator(TL, TL.getNumArgs()),
5326 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005327 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005328
John McCall0ad16662009-10-29 08:12:44 +00005329 // FIXME: maybe don't rebuild if all the template arguments are the same.
5330
5331 QualType Result =
5332 getDerived().RebuildTemplateSpecializationType(Template,
5333 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005334 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005335
5336 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005337 // Specializations of template template parameters are represented as
5338 // TemplateSpecializationTypes, and substitution of type alias templates
5339 // within a dependent context can transform them into
5340 // DependentTemplateSpecializationTypes.
5341 if (isa<DependentTemplateSpecializationType>(Result)) {
5342 DependentTemplateSpecializationTypeLoc NewTL
5343 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005344 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005345 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005346 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005347 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005348 NewTL.setLAngleLoc(TL.getLAngleLoc());
5349 NewTL.setRAngleLoc(TL.getRAngleLoc());
5350 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5351 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5352 return Result;
5353 }
5354
John McCall0ad16662009-10-29 08:12:44 +00005355 TemplateSpecializationTypeLoc NewTL
5356 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005357 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005358 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5359 NewTL.setLAngleLoc(TL.getLAngleLoc());
5360 NewTL.setRAngleLoc(TL.getRAngleLoc());
5361 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5362 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005363 }
Mike Stump11289f42009-09-09 15:08:12 +00005364
John McCall0ad16662009-10-29 08:12:44 +00005365 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005366}
Mike Stump11289f42009-09-09 15:08:12 +00005367
Douglas Gregor5a064722011-02-28 17:23:35 +00005368template <typename Derived>
5369QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5370 TypeLocBuilder &TLB,
5371 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005372 TemplateName Template,
5373 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005374 TemplateArgumentListInfo NewTemplateArgs;
5375 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5376 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5377 typedef TemplateArgumentLocContainerIterator<
5378 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005379 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005380 ArgIterator(TL, TL.getNumArgs()),
5381 NewTemplateArgs))
5382 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005383
Douglas Gregor5a064722011-02-28 17:23:35 +00005384 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005385
Douglas Gregor5a064722011-02-28 17:23:35 +00005386 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5387 QualType Result
5388 = getSema().Context.getDependentTemplateSpecializationType(
5389 TL.getTypePtr()->getKeyword(),
5390 DTN->getQualifier(),
5391 DTN->getIdentifier(),
5392 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005393
Douglas Gregor5a064722011-02-28 17:23:35 +00005394 DependentTemplateSpecializationTypeLoc NewTL
5395 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005396 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005397 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005398 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005399 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005400 NewTL.setLAngleLoc(TL.getLAngleLoc());
5401 NewTL.setRAngleLoc(TL.getRAngleLoc());
5402 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5403 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5404 return Result;
5405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005406
5407 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005408 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005409 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005410 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
Douglas Gregor5a064722011-02-28 17:23:35 +00005412 if (!Result.isNull()) {
5413 /// FIXME: Wrap this in an elaborated-type-specifier?
5414 TemplateSpecializationTypeLoc NewTL
5415 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005416 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005417 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +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 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005423
Douglas Gregor5a064722011-02-28 17:23:35 +00005424 return Result;
5425}
5426
Mike Stump11289f42009-09-09 15:08:12 +00005427template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005428QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005429TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005430 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005431 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005432
Douglas Gregor844cb502011-03-01 18:12:44 +00005433 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005434 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005435 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005436 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005437 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5438 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005439 return QualType();
5440 }
Mike Stump11289f42009-09-09 15:08:12 +00005441
John McCall31f82722010-11-12 08:19:04 +00005442 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5443 if (NamedT.isNull())
5444 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005445
Richard Smith3f1b5d02011-05-05 21:57:07 +00005446 // C++0x [dcl.type.elab]p2:
5447 // If the identifier resolves to a typedef-name or the simple-template-id
5448 // resolves to an alias template specialization, the
5449 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005450 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5451 if (const TemplateSpecializationType *TST =
5452 NamedT->getAs<TemplateSpecializationType>()) {
5453 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005454 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5455 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005456 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5457 diag::err_tag_reference_non_tag) << 4;
5458 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5459 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005460 }
5461 }
5462
John McCall550e0c22009-10-21 00:40:46 +00005463 QualType Result = TL.getType();
5464 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005465 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005466 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005467 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005468 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005469 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005470 if (Result.isNull())
5471 return QualType();
5472 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005473
Abramo Bagnara6150c882010-05-11 21:36:43 +00005474 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005475 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005476 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005477 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005478}
Mike Stump11289f42009-09-09 15:08:12 +00005479
5480template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005481QualType TreeTransform<Derived>::TransformAttributedType(
5482 TypeLocBuilder &TLB,
5483 AttributedTypeLoc TL) {
5484 const AttributedType *oldType = TL.getTypePtr();
5485 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5486 if (modifiedType.isNull())
5487 return QualType();
5488
5489 QualType result = TL.getType();
5490
5491 // FIXME: dependent operand expressions?
5492 if (getDerived().AlwaysRebuild() ||
5493 modifiedType != oldType->getModifiedType()) {
5494 // TODO: this is really lame; we should really be rebuilding the
5495 // equivalent type from first principles.
5496 QualType equivalentType
5497 = getDerived().TransformType(oldType->getEquivalentType());
5498 if (equivalentType.isNull())
5499 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005500
5501 // Check whether we can add nullability; it is only represented as
5502 // type sugar, and therefore cannot be diagnosed in any other way.
5503 if (auto nullability = oldType->getImmediateNullability()) {
5504 if (!modifiedType->canHaveNullability()) {
5505 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005506 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005507 return QualType();
5508 }
5509 }
5510
John McCall81904512011-01-06 01:58:22 +00005511 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5512 modifiedType,
5513 equivalentType);
5514 }
5515
5516 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5517 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5518 if (TL.hasAttrOperand())
5519 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5520 if (TL.hasAttrExprOperand())
5521 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5522 else if (TL.hasAttrEnumOperand())
5523 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5524
5525 return result;
5526}
5527
5528template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005529QualType
5530TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5531 ParenTypeLoc TL) {
5532 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5533 if (Inner.isNull())
5534 return QualType();
5535
5536 QualType Result = TL.getType();
5537 if (getDerived().AlwaysRebuild() ||
5538 Inner != TL.getInnerLoc().getType()) {
5539 Result = getDerived().RebuildParenType(Inner);
5540 if (Result.isNull())
5541 return QualType();
5542 }
5543
5544 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5545 NewTL.setLParenLoc(TL.getLParenLoc());
5546 NewTL.setRParenLoc(TL.getRParenLoc());
5547 return Result;
5548}
5549
5550template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005551QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005552 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005553 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005554
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005555 NestedNameSpecifierLoc QualifierLoc
5556 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5557 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005558 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005559
John McCallc392f372010-06-11 00:33:02 +00005560 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005561 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005562 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005563 QualifierLoc,
5564 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005565 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005566 if (Result.isNull())
5567 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005568
Abramo Bagnarad7548482010-05-19 21:37:53 +00005569 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5570 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005571 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5572
Abramo Bagnarad7548482010-05-19 21:37:53 +00005573 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005574 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005575 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005576 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005577 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005578 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005579 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005580 NewTL.setNameLoc(TL.getNameLoc());
5581 }
John McCall550e0c22009-10-21 00:40:46 +00005582 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005583}
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregord6ff3322009-08-04 16:50:30 +00005585template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005586QualType TreeTransform<Derived>::
5587 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005588 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005589 NestedNameSpecifierLoc QualifierLoc;
5590 if (TL.getQualifierLoc()) {
5591 QualifierLoc
5592 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5593 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005594 return QualType();
5595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005596
John McCall31f82722010-11-12 08:19:04 +00005597 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005598 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005599}
5600
5601template<typename Derived>
5602QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005603TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5604 DependentTemplateSpecializationTypeLoc TL,
5605 NestedNameSpecifierLoc QualifierLoc) {
5606 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005607
Douglas Gregora7a795b2011-03-01 20:11:18 +00005608 TemplateArgumentListInfo NewTemplateArgs;
5609 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5610 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005611
Douglas Gregora7a795b2011-03-01 20:11:18 +00005612 typedef TemplateArgumentLocContainerIterator<
5613 DependentTemplateSpecializationTypeLoc> ArgIterator;
5614 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5615 ArgIterator(TL, TL.getNumArgs()),
5616 NewTemplateArgs))
5617 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005618
Douglas Gregora7a795b2011-03-01 20:11:18 +00005619 QualType Result
5620 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5621 QualifierLoc,
5622 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005623 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005624 NewTemplateArgs);
5625 if (Result.isNull())
5626 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005627
Douglas Gregora7a795b2011-03-01 20:11:18 +00005628 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5629 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005630
Douglas Gregora7a795b2011-03-01 20:11:18 +00005631 // Copy information relevant to the template specialization.
5632 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005633 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005634 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005635 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005636 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5637 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005638 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005639 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005640
Douglas Gregora7a795b2011-03-01 20:11:18 +00005641 // Copy information relevant to the elaborated type.
5642 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005643 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005644 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005645 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5646 DependentTemplateSpecializationTypeLoc SpecTL
5647 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005648 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005649 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005650 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005651 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005652 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5653 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005654 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005655 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005656 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005657 TemplateSpecializationTypeLoc SpecTL
5658 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005659 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005660 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005661 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5662 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005663 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005664 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005665 }
5666 return Result;
5667}
5668
5669template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005670QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5671 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005672 QualType Pattern
5673 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005674 if (Pattern.isNull())
5675 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005676
5677 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005678 if (getDerived().AlwaysRebuild() ||
5679 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005680 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005681 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005682 TL.getEllipsisLoc(),
5683 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005684 if (Result.isNull())
5685 return QualType();
5686 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005687
Douglas Gregor822d0302011-01-12 17:07:58 +00005688 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5689 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5690 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005691}
5692
5693template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005694QualType
5695TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005696 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005697 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005698 TLB.pushFullCopy(TL);
5699 return TL.getType();
5700}
5701
5702template<typename Derived>
5703QualType
5704TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005705 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005706 // Transform base type.
5707 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5708 if (BaseType.isNull())
5709 return QualType();
5710
5711 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5712
5713 // Transform type arguments.
5714 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5715 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5716 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5717 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5718 QualType TypeArg = TypeArgInfo->getType();
5719 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5720 AnyChanged = true;
5721
5722 // We have a pack expansion. Instantiate it.
5723 const auto *PackExpansion = PackExpansionLoc.getType()
5724 ->castAs<PackExpansionType>();
5725 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5726 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5727 Unexpanded);
5728 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5729
5730 // Determine whether the set of unexpanded parameter packs can
5731 // and should be expanded.
5732 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5733 bool Expand = false;
5734 bool RetainExpansion = false;
5735 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5736 if (getDerived().TryExpandParameterPacks(
5737 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5738 Unexpanded, Expand, RetainExpansion, NumExpansions))
5739 return QualType();
5740
5741 if (!Expand) {
5742 // We can't expand this pack expansion into separate arguments yet;
5743 // just substitute into the pattern and create a new pack expansion
5744 // type.
5745 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5746
5747 TypeLocBuilder TypeArgBuilder;
5748 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5749 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5750 PatternLoc);
5751 if (NewPatternType.isNull())
5752 return QualType();
5753
5754 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5755 NewPatternType, NumExpansions);
5756 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5757 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5758 NewTypeArgInfos.push_back(
5759 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5760 continue;
5761 }
5762
5763 // Substitute into the pack expansion pattern for each slice of the
5764 // pack.
5765 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5766 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5767
5768 TypeLocBuilder TypeArgBuilder;
5769 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5770
5771 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5772 PatternLoc);
5773 if (NewTypeArg.isNull())
5774 return QualType();
5775
5776 NewTypeArgInfos.push_back(
5777 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5778 }
5779
5780 continue;
5781 }
5782
5783 TypeLocBuilder TypeArgBuilder;
5784 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5785 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5786 if (NewTypeArg.isNull())
5787 return QualType();
5788
5789 // If nothing changed, just keep the old TypeSourceInfo.
5790 if (NewTypeArg == TypeArg) {
5791 NewTypeArgInfos.push_back(TypeArgInfo);
5792 continue;
5793 }
5794
5795 NewTypeArgInfos.push_back(
5796 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5797 AnyChanged = true;
5798 }
5799
5800 QualType Result = TL.getType();
5801 if (getDerived().AlwaysRebuild() || AnyChanged) {
5802 // Rebuild the type.
5803 Result = getDerived().RebuildObjCObjectType(
5804 BaseType,
5805 TL.getLocStart(),
5806 TL.getTypeArgsLAngleLoc(),
5807 NewTypeArgInfos,
5808 TL.getTypeArgsRAngleLoc(),
5809 TL.getProtocolLAngleLoc(),
5810 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5811 TL.getNumProtocols()),
5812 TL.getProtocolLocs(),
5813 TL.getProtocolRAngleLoc());
5814
5815 if (Result.isNull())
5816 return QualType();
5817 }
5818
5819 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5820 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5821 NewT.setHasBaseTypeAsWritten(true);
5822 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5823 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5824 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5825 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5826 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5827 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5828 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5829 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5830 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
5833template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005834QualType
5835TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005836 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005837 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5838 if (PointeeType.isNull())
5839 return QualType();
5840
5841 QualType Result = TL.getType();
5842 if (getDerived().AlwaysRebuild() ||
5843 PointeeType != TL.getPointeeLoc().getType()) {
5844 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5845 TL.getStarLoc());
5846 if (Result.isNull())
5847 return QualType();
5848 }
5849
5850 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5851 NewT.setStarLoc(TL.getStarLoc());
5852 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005853}
5854
Douglas Gregord6ff3322009-08-04 16:50:30 +00005855//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005856// Statement transformation
5857//===----------------------------------------------------------------------===//
5858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005859StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005860TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005861 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005862}
5863
5864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005865StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005866TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5867 return getDerived().TransformCompoundStmt(S, false);
5868}
5869
5870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005871StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005872TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005873 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005874 Sema::CompoundScopeRAII CompoundScope(getSema());
5875
John McCall1ababa62010-08-27 19:56:05 +00005876 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005877 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005878 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005879 for (auto *B : S->body()) {
5880 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005881 if (Result.isInvalid()) {
5882 // Immediately fail if this was a DeclStmt, since it's very
5883 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005884 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005885 return StmtError();
5886
5887 // Otherwise, just keep processing substatements and fail later.
5888 SubStmtInvalid = true;
5889 continue;
5890 }
Mike Stump11289f42009-09-09 15:08:12 +00005891
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005892 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005893 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005894 }
Mike Stump11289f42009-09-09 15:08:12 +00005895
John McCall1ababa62010-08-27 19:56:05 +00005896 if (SubStmtInvalid)
5897 return StmtError();
5898
Douglas Gregorebe10102009-08-20 07:17:43 +00005899 if (!getDerived().AlwaysRebuild() &&
5900 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005901 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005902
5903 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005904 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005905 S->getRBracLoc(),
5906 IsStmtExpr);
5907}
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregorebe10102009-08-20 07:17:43 +00005909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005910StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005911TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005912 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005913 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005914 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5915 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005916
Eli Friedman06577382009-11-19 03:14:00 +00005917 // Transform the left-hand case value.
5918 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005919 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005920 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Eli Friedman06577382009-11-19 03:14:00 +00005923 // Transform the right-hand case value (for the GNU case-range extension).
5924 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005925 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005926 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005927 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005928 }
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 // Build the case statement.
5931 // Case statements are always rebuilt so that they will attached to their
5932 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005933 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005934 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005935 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005936 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005937 S->getColonLoc());
5938 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorebe10102009-08-20 07:17:43 +00005941 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005942 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005944 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005945
Douglas Gregorebe10102009-08-20 07:17:43 +00005946 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005947 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005948}
5949
5950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005951StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005952TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005953 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005954 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005955 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregorebe10102009-08-20 07:17:43 +00005958 // Default statements are always rebuilt
5959 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005960 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005961}
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregorebe10102009-08-20 07:17:43 +00005963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005964StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005965TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005966 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005967 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005969
Chris Lattnercab02a62011-02-17 20:34:02 +00005970 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5971 S->getDecl());
5972 if (!LD)
5973 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005974
5975
Douglas Gregorebe10102009-08-20 07:17:43 +00005976 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005977 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005978 cast<LabelDecl>(LD), SourceLocation(),
5979 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005980}
Mike Stump11289f42009-09-09 15:08:12 +00005981
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005982template <typename Derived>
5983const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5984 if (!R)
5985 return R;
5986
5987 switch (R->getKind()) {
5988// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5989#define ATTR(X)
5990#define PRAGMA_SPELLING_ATTR(X) \
5991 case attr::X: \
5992 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5993#include "clang/Basic/AttrList.inc"
5994 default:
5995 return R;
5996 }
5997}
5998
5999template <typename Derived>
6000StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6001 bool AttrsChanged = false;
6002 SmallVector<const Attr *, 1> Attrs;
6003
6004 // Visit attributes and keep track if any are transformed.
6005 for (const auto *I : S->getAttrs()) {
6006 const Attr *R = getDerived().TransformAttr(I);
6007 AttrsChanged |= (I != R);
6008 Attrs.push_back(R);
6009 }
6010
Richard Smithc202b282012-04-14 00:33:13 +00006011 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6012 if (SubStmt.isInvalid())
6013 return StmtError();
6014
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006015 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006016 return S;
6017
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006018 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006019 SubStmt.get());
6020}
6021
6022template<typename Derived>
6023StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006024TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006025 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006026 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006027 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006028 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006029 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006030 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006031 getDerived().TransformDefinition(
6032 S->getConditionVariable()->getLocation(),
6033 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006034 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006036 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006037 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006038
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006039 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006041
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006042 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006043 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006044 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006045 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006046 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006048
John McCallb268a282010-08-23 23:25:46 +00006049 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006050 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006051 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006052
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006053 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006054 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006055 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006056
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006058 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006059 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006061
Douglas Gregorebe10102009-08-20 07:17:43 +00006062 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006063 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006065 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006068 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006069 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 Then.get() == S->getThen() &&
6071 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006072 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006074 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006075 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006076 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006077}
6078
6079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006080StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006081TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006083 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006084 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006085 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006086 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006087 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006088 getDerived().TransformDefinition(
6089 S->getConditionVariable()->getLocation(),
6090 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006091 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006092 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006093 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006094 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006095
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006096 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006098 }
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006101 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006102 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006103 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006104 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregorebe10102009-08-20 07:17:43 +00006107 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006108 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006109 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregorebe10102009-08-20 07:17:43 +00006112 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006113 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6114 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006115}
Mike Stump11289f42009-09-09 15:08:12 +00006116
Douglas Gregorebe10102009-08-20 07:17:43 +00006117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006118StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006119TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006120 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006122 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006123 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006124 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006125 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006126 getDerived().TransformDefinition(
6127 S->getConditionVariable()->getLocation(),
6128 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006129 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006131 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006132 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006133
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006134 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006136
6137 if (S->getCond()) {
6138 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006139 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6140 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006141 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006142 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006144 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006145 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006146 }
Mike Stump11289f42009-09-09 15:08:12 +00006147
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006148 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006149 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006150 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006151
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006153 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006154 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006158 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006159 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006161 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006162
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006163 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006164 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006165}
Mike Stump11289f42009-09-09 15:08:12 +00006166
Douglas Gregorebe10102009-08-20 07:17:43 +00006167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006168StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006169TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006171 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006174
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006175 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006176 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006177 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregorebe10102009-08-20 07:17:43 +00006180 if (!getDerived().AlwaysRebuild() &&
6181 Cond.get() == S->getCond() &&
6182 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006183 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006184
John McCallb268a282010-08-23 23:25:46 +00006185 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6186 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 S->getRParenLoc());
6188}
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006191StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006192TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006193 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006194 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006196 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006199 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006200 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006201 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006202 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006203 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006204 getDerived().TransformDefinition(
6205 S->getConditionVariable()->getLocation(),
6206 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006207 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006209 } else {
6210 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006211
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006212 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006214
6215 if (S->getCond()) {
6216 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006217 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6218 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006219 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006220 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006221 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006222
John McCallb268a282010-08-23 23:25:46 +00006223 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006224 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006225 }
Mike Stump11289f42009-09-09 15:08:12 +00006226
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006227 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006228 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006229 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006230
Douglas Gregorebe10102009-08-20 07:17:43 +00006231 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006232 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006233 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006234 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006235
Richard Smith945f8d32013-01-14 22:39:08 +00006236 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006237 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006239
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 Gregorebe10102009-08-20 07:17:43 +00006245 if (!getDerived().AlwaysRebuild() &&
6246 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006247 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 Inc.get() == S->getInc() &&
6249 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006250 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregorebe10102009-08-20 07:17:43 +00006252 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006253 Init.get(), FullCond, ConditionVar,
6254 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006255}
6256
6257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006259TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006260 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6261 S->getLabel());
6262 if (!LD)
6263 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006266 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006267 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006268}
6269
6270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006271StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006272TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006273 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006274 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006275 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006276 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregorebe10102009-08-20 07:17:43 +00006278 if (!getDerived().AlwaysRebuild() &&
6279 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006280 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006281
6282 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006283 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006284}
6285
6286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006287StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006288TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006289 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006293StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006294TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006295 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006296}
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregorebe10102009-08-20 07:17:43 +00006298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006299StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006300TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006301 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6302 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006303 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006305
Mike Stump11289f42009-09-09 15:08:12 +00006306 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006307 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006308 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006309}
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregorebe10102009-08-20 07:17:43 +00006311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006312StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006313TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006314 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006315 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006316 for (auto *D : S->decls()) {
6317 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006318 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006320
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006321 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006323
Douglas Gregorebe10102009-08-20 07:17:43 +00006324 Decls.push_back(Transformed);
6325 }
Mike Stump11289f42009-09-09 15:08:12 +00006326
Douglas Gregorebe10102009-08-20 07:17:43 +00006327 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006328 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006329
Rafael Espindolaab417692013-07-09 12:05:01 +00006330 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006331}
Mike Stump11289f42009-09-09 15:08:12 +00006332
Douglas Gregorebe10102009-08-20 07:17:43 +00006333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006334StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006335TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006336
Benjamin Kramerf0623432012-08-23 22:51:59 +00006337 SmallVector<Expr*, 8> Constraints;
6338 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006339 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006340
John McCalldadc5752010-08-24 06:29:42 +00006341 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006342 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006343
6344 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006345
Anders Carlssonaaeef072010-01-24 05:50:09 +00006346 // Go through the outputs.
6347 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006348 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006349
Anders Carlssonaaeef072010-01-24 05:50:09 +00006350 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006351 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006352
Anders Carlssonaaeef072010-01-24 05:50:09 +00006353 // Transform the output expr.
6354 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006355 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006356 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006358
Anders Carlssonaaeef072010-01-24 05:50:09 +00006359 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006360
John McCallb268a282010-08-23 23:25:46 +00006361 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006363
Anders Carlssonaaeef072010-01-24 05:50:09 +00006364 // Go through the inputs.
6365 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006366 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006367
Anders Carlssonaaeef072010-01-24 05:50:09 +00006368 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006369 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006370
Anders Carlssonaaeef072010-01-24 05:50:09 +00006371 // Transform the input expr.
6372 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006373 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006374 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006376
Anders Carlssonaaeef072010-01-24 05:50:09 +00006377 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006378
John McCallb268a282010-08-23 23:25:46 +00006379 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006381
Anders Carlssonaaeef072010-01-24 05:50:09 +00006382 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006383 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006384
6385 // Go through the clobbers.
6386 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006387 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006388
6389 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006390 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006391 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6392 S->isVolatile(), S->getNumOutputs(),
6393 S->getNumInputs(), Names.data(),
6394 Constraints, Exprs, AsmString.get(),
6395 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006396}
6397
Chad Rosier32503022012-06-11 20:47:18 +00006398template<typename Derived>
6399StmtResult
6400TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006401 ArrayRef<Token> AsmToks =
6402 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006403
John McCallf413f5e2013-05-03 00:10:13 +00006404 bool HadError = false, HadChange = false;
6405
6406 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6407 SmallVector<Expr*, 8> TransformedExprs;
6408 TransformedExprs.reserve(SrcExprs.size());
6409 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6410 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6411 if (!Result.isUsable()) {
6412 HadError = true;
6413 } else {
6414 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006415 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006416 }
6417 }
6418
6419 if (HadError) return StmtError();
6420 if (!HadChange && !getDerived().AlwaysRebuild())
6421 return Owned(S);
6422
Chad Rosierb6f46c12012-08-15 16:53:30 +00006423 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006424 AsmToks, S->getAsmString(),
6425 S->getNumOutputs(), S->getNumInputs(),
6426 S->getAllConstraints(), S->getClobbers(),
6427 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006428}
Douglas Gregorebe10102009-08-20 07:17:43 +00006429
Richard Smith9f690bd2015-10-27 06:02:45 +00006430// C++ Coroutines TS
6431
6432template<typename Derived>
6433StmtResult
6434TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6435 // The coroutine body should be re-formed by the caller if necessary.
6436 return getDerived().TransformStmt(S->getBody());
6437}
6438
6439template<typename Derived>
6440StmtResult
6441TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6442 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6443 /*NotCopyInit*/false);
6444 if (Result.isInvalid())
6445 return StmtError();
6446
6447 // Always rebuild; we don't know if this needs to be injected into a new
6448 // context or if the promise type has changed.
6449 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6450}
6451
6452template<typename Derived>
6453ExprResult
6454TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6455 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6456 /*NotCopyInit*/false);
6457 if (Result.isInvalid())
6458 return ExprError();
6459
6460 // Always rebuild; we don't know if this needs to be injected into a new
6461 // context or if the promise type has changed.
6462 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6463}
6464
6465template<typename Derived>
6466ExprResult
6467TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6468 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6469 /*NotCopyInit*/false);
6470 if (Result.isInvalid())
6471 return ExprError();
6472
6473 // Always rebuild; we don't know if this needs to be injected into a new
6474 // context or if the promise type has changed.
6475 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6476}
6477
6478// Objective-C Statements.
6479
Douglas Gregorebe10102009-08-20 07:17:43 +00006480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006481StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006482TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006483 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006484 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006485 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006486 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006487
Douglas Gregor96c79492010-04-23 22:50:49 +00006488 // Transform the @catch statements (if present).
6489 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006490 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006491 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006492 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006493 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006494 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006495 if (Catch.get() != S->getCatchStmt(I))
6496 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006497 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006499
Douglas Gregor306de2f2010-04-22 23:59:56 +00006500 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006501 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006502 if (S->getFinallyStmt()) {
6503 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6504 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006505 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006506 }
6507
6508 // If nothing changed, just retain this statement.
6509 if (!getDerived().AlwaysRebuild() &&
6510 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006511 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006512 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006513 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006514
Douglas Gregor306de2f2010-04-22 23:59:56 +00006515 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006516 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006517 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006518}
Mike Stump11289f42009-09-09 15:08:12 +00006519
Douglas Gregorebe10102009-08-20 07:17:43 +00006520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006521StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006522TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006523 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006524 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006525 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006526 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006527 if (FromVar->getTypeSourceInfo()) {
6528 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6529 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006532
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006533 QualType T;
6534 if (TSInfo)
6535 T = TSInfo->getType();
6536 else {
6537 T = getDerived().TransformType(FromVar->getType());
6538 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006539 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006541
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006542 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6543 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006546
John McCalldadc5752010-08-24 06:29:42 +00006547 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006548 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006549 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006550
6551 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006552 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006553 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006554}
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregorebe10102009-08-20 07:17:43 +00006556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006557StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006558TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006559 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006560 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006561 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006562 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006563
Douglas Gregor306de2f2010-04-22 23:59:56 +00006564 // If nothing changed, just retain this statement.
6565 if (!getDerived().AlwaysRebuild() &&
6566 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006567 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006568
6569 // Build a new statement.
6570 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006571 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006572}
Mike Stump11289f42009-09-09 15:08:12 +00006573
Douglas Gregorebe10102009-08-20 07:17:43 +00006574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006575StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006576TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006577 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006578 if (S->getThrowExpr()) {
6579 Operand = getDerived().TransformExpr(S->getThrowExpr());
6580 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006583
Douglas Gregor2900c162010-04-22 21:44:01 +00006584 if (!getDerived().AlwaysRebuild() &&
6585 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006586 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006587
John McCallb268a282010-08-23 23:25:46 +00006588 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006589}
Mike Stump11289f42009-09-09 15:08:12 +00006590
Douglas Gregorebe10102009-08-20 07:17:43 +00006591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006592StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006593TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006594 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006595 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006596 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006597 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006598 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006599 Object =
6600 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6601 Object.get());
6602 if (Object.isInvalid())
6603 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006604
Douglas Gregor6148de72010-04-22 22:01:21 +00006605 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006606 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006607 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006608 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006609
Douglas Gregor6148de72010-04-22 22:01:21 +00006610 // If nothing change, just retain the current statement.
6611 if (!getDerived().AlwaysRebuild() &&
6612 Object.get() == S->getSynchExpr() &&
6613 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006614 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006615
6616 // Build a new statement.
6617 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006618 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006619}
6620
6621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006622StmtResult
John McCall31168b02011-06-15 23:02:42 +00006623TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6624 ObjCAutoreleasePoolStmt *S) {
6625 // Transform the body.
6626 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6627 if (Body.isInvalid())
6628 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006629
John McCall31168b02011-06-15 23:02:42 +00006630 // If nothing changed, just retain this statement.
6631 if (!getDerived().AlwaysRebuild() &&
6632 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006633 return S;
John McCall31168b02011-06-15 23:02:42 +00006634
6635 // Build a new statement.
6636 return getDerived().RebuildObjCAutoreleasePoolStmt(
6637 S->getAtLoc(), Body.get());
6638}
6639
6640template<typename Derived>
6641StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006642TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006643 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006644 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006645 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006646 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006647 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006648
Douglas Gregorf68a5082010-04-22 23:10:45 +00006649 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006650 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006651 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006653
Douglas Gregorf68a5082010-04-22 23:10:45 +00006654 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006655 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006656 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006657 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006658
Douglas Gregorf68a5082010-04-22 23:10:45 +00006659 // If nothing changed, just retain this statement.
6660 if (!getDerived().AlwaysRebuild() &&
6661 Element.get() == S->getElement() &&
6662 Collection.get() == S->getCollection() &&
6663 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006664 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006665
Douglas Gregorf68a5082010-04-22 23:10:45 +00006666 // Build a new statement.
6667 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006668 Element.get(),
6669 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006670 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006671 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006672}
6673
David Majnemer5f7efef2013-10-15 09:50:08 +00006674template <typename Derived>
6675StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006676 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006677 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006678 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6679 TypeSourceInfo *T =
6680 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006681 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006683
David Majnemer5f7efef2013-10-15 09:50:08 +00006684 Var = getDerived().RebuildExceptionDecl(
6685 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6686 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006687 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006689 }
Mike Stump11289f42009-09-09 15:08:12 +00006690
Douglas Gregorebe10102009-08-20 07:17:43 +00006691 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006692 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006693 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006694 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006695
David Majnemer5f7efef2013-10-15 09:50:08 +00006696 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006697 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006698 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006699
David Majnemer5f7efef2013-10-15 09:50:08 +00006700 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006701}
Mike Stump11289f42009-09-09 15:08:12 +00006702
David Majnemer5f7efef2013-10-15 09:50:08 +00006703template <typename Derived>
6704StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006705 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006706 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006707 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006708 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregorebe10102009-08-20 07:17:43 +00006710 // Transform the handlers.
6711 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006712 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006713 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006714 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006715 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregorebe10102009-08-20 07:17:43 +00006718 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006719 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006720 }
Mike Stump11289f42009-09-09 15:08:12 +00006721
David Majnemer5f7efef2013-10-15 09:50:08 +00006722 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006723 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006724 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006725
John McCallb268a282010-08-23 23:25:46 +00006726 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006727 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006728}
Mike Stump11289f42009-09-09 15:08:12 +00006729
Richard Smith02e85f32011-04-14 22:09:26 +00006730template<typename Derived>
6731StmtResult
6732TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6733 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6734 if (Range.isInvalid())
6735 return StmtError();
6736
6737 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6738 if (BeginEnd.isInvalid())
6739 return StmtError();
6740
6741 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6742 if (Cond.isInvalid())
6743 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006744 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006745 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006746 if (Cond.isInvalid())
6747 return StmtError();
6748 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006749 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006750
6751 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6752 if (Inc.isInvalid())
6753 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006754 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006755 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006756
6757 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6758 if (LoopVar.isInvalid())
6759 return StmtError();
6760
6761 StmtResult NewStmt = S;
6762 if (getDerived().AlwaysRebuild() ||
6763 Range.get() != S->getRangeStmt() ||
6764 BeginEnd.get() != S->getBeginEndStmt() ||
6765 Cond.get() != S->getCond() ||
6766 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006767 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006768 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006769 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006770 S->getColonLoc(), Range.get(),
6771 BeginEnd.get(), Cond.get(),
6772 Inc.get(), LoopVar.get(),
6773 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006774 if (NewStmt.isInvalid())
6775 return StmtError();
6776 }
Richard Smith02e85f32011-04-14 22:09:26 +00006777
6778 StmtResult Body = getDerived().TransformStmt(S->getBody());
6779 if (Body.isInvalid())
6780 return StmtError();
6781
6782 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6783 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006784 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006785 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006786 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006787 S->getColonLoc(), Range.get(),
6788 BeginEnd.get(), Cond.get(),
6789 Inc.get(), LoopVar.get(),
6790 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006791 if (NewStmt.isInvalid())
6792 return StmtError();
6793 }
Richard Smith02e85f32011-04-14 22:09:26 +00006794
6795 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006796 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006797
6798 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6799}
6800
John Wiegley1c0675e2011-04-28 01:08:34 +00006801template<typename Derived>
6802StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006803TreeTransform<Derived>::TransformMSDependentExistsStmt(
6804 MSDependentExistsStmt *S) {
6805 // Transform the nested-name-specifier, if any.
6806 NestedNameSpecifierLoc QualifierLoc;
6807 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006808 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006809 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6810 if (!QualifierLoc)
6811 return StmtError();
6812 }
6813
6814 // Transform the declaration name.
6815 DeclarationNameInfo NameInfo = S->getNameInfo();
6816 if (NameInfo.getName()) {
6817 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6818 if (!NameInfo.getName())
6819 return StmtError();
6820 }
6821
6822 // Check whether anything changed.
6823 if (!getDerived().AlwaysRebuild() &&
6824 QualifierLoc == S->getQualifierLoc() &&
6825 NameInfo.getName() == S->getNameInfo().getName())
6826 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006827
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006828 // Determine whether this name exists, if we can.
6829 CXXScopeSpec SS;
6830 SS.Adopt(QualifierLoc);
6831 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006832 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006833 case Sema::IER_Exists:
6834 if (S->isIfExists())
6835 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006836
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006837 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6838
6839 case Sema::IER_DoesNotExist:
6840 if (S->isIfNotExists())
6841 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006842
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006843 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006844
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006845 case Sema::IER_Dependent:
6846 Dependent = true;
6847 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006848
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006849 case Sema::IER_Error:
6850 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006852
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006853 // We need to continue with the instantiation, so do so now.
6854 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6855 if (SubStmt.isInvalid())
6856 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006857
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006858 // If we have resolved the name, just transform to the substatement.
6859 if (!Dependent)
6860 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006861
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006862 // The name is still dependent, so build a dependent expression again.
6863 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6864 S->isIfExists(),
6865 QualifierLoc,
6866 NameInfo,
6867 SubStmt.get());
6868}
6869
6870template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006871ExprResult
6872TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6873 NestedNameSpecifierLoc QualifierLoc;
6874 if (E->getQualifierLoc()) {
6875 QualifierLoc
6876 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6877 if (!QualifierLoc)
6878 return ExprError();
6879 }
6880
6881 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6882 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6883 if (!PD)
6884 return ExprError();
6885
6886 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6887 if (Base.isInvalid())
6888 return ExprError();
6889
6890 return new (SemaRef.getASTContext())
6891 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6892 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6893 QualifierLoc, E->getMemberLoc());
6894}
6895
David Majnemerfad8f482013-10-15 09:33:02 +00006896template <typename Derived>
6897StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006898 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006899 if (TryBlock.isInvalid())
6900 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006901
6902 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006903 if (Handler.isInvalid())
6904 return StmtError();
6905
David Majnemerfad8f482013-10-15 09:33:02 +00006906 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6907 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006908 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006909
Warren Huntf6be4cb2014-07-25 20:52:51 +00006910 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6911 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006912}
6913
David Majnemerfad8f482013-10-15 09:33:02 +00006914template <typename Derived>
6915StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006916 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006917 if (Block.isInvalid())
6918 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006919
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006920 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006921}
6922
David Majnemerfad8f482013-10-15 09:33:02 +00006923template <typename Derived>
6924StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006925 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006926 if (FilterExpr.isInvalid())
6927 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006928
David Majnemer7e755502013-10-15 09:30:14 +00006929 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006930 if (Block.isInvalid())
6931 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006932
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006933 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6934 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006935}
6936
David Majnemerfad8f482013-10-15 09:33:02 +00006937template <typename Derived>
6938StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6939 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006940 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6941 else
6942 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6943}
6944
Nico Weber9b982072014-07-07 00:12:30 +00006945template<typename Derived>
6946StmtResult
6947TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6948 return S;
6949}
6950
Alexander Musman64d33f12014-06-04 07:53:32 +00006951//===----------------------------------------------------------------------===//
6952// OpenMP directive transformation
6953//===----------------------------------------------------------------------===//
6954template <typename Derived>
6955StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6956 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006957
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006958 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006959 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006960 ArrayRef<OMPClause *> Clauses = D->clauses();
6961 TClauses.reserve(Clauses.size());
6962 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6963 I != E; ++I) {
6964 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006965 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006966 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006967 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006968 if (Clause)
6969 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006970 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006971 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006972 }
6973 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006974 StmtResult AssociatedStmt;
6975 if (D->hasAssociatedStmt()) {
6976 if (!D->getAssociatedStmt()) {
6977 return StmtError();
6978 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006979 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6980 /*CurScope=*/nullptr);
6981 StmtResult Body;
6982 {
6983 Sema::CompoundScopeRAII CompoundScope(getSema());
6984 Body = getDerived().TransformStmt(
6985 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6986 }
6987 AssociatedStmt =
6988 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006989 if (AssociatedStmt.isInvalid()) {
6990 return StmtError();
6991 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006992 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006993 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006994 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006995 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006996
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006997 // Transform directive name for 'omp critical' directive.
6998 DeclarationNameInfo DirName;
6999 if (D->getDirectiveKind() == OMPD_critical) {
7000 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7001 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7002 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007003 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7004 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7005 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007006 } else if (D->getDirectiveKind() == OMPD_cancel) {
7007 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007008 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007009
Alexander Musman64d33f12014-06-04 07:53:32 +00007010 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007011 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7012 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007013}
7014
Alexander Musman64d33f12014-06-04 07:53:32 +00007015template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007016StmtResult
7017TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7018 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007019 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7020 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7023 return Res;
7024}
7025
Alexander Musman64d33f12014-06-04 07:53:32 +00007026template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007027StmtResult
7028TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7029 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007030 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7031 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007034 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007035}
7036
Alexey Bataevf29276e2014-06-18 04:14:57 +00007037template <typename Derived>
7038StmtResult
7039TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7040 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007041 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7042 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7045 return Res;
7046}
7047
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007048template <typename Derived>
7049StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007050TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7051 DeclarationNameInfo DirName;
7052 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7053 D->getLocStart());
7054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7056 return Res;
7057}
7058
7059template <typename Derived>
7060StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007061TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7062 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007063 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7064 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7067 return Res;
7068}
7069
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007070template <typename Derived>
7071StmtResult
7072TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7073 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007074 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7075 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7078 return Res;
7079}
7080
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007081template <typename Derived>
7082StmtResult
7083TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7084 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007085 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7086 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7089 return Res;
7090}
7091
Alexey Bataev4acb8592014-07-07 13:01:15 +00007092template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007093StmtResult
7094TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7095 DeclarationNameInfo DirName;
7096 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7097 D->getLocStart());
7098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7100 return Res;
7101}
7102
7103template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007104StmtResult
7105TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7106 getDerived().getSema().StartOpenMPDSABlock(
7107 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7108 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7109 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7110 return Res;
7111}
7112
7113template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007114StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7115 OMPParallelForDirective *D) {
7116 DeclarationNameInfo DirName;
7117 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7118 nullptr, D->getLocStart());
7119 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7120 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7121 return Res;
7122}
7123
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007124template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007125StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7126 OMPParallelForSimdDirective *D) {
7127 DeclarationNameInfo DirName;
7128 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7129 nullptr, D->getLocStart());
7130 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7131 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7132 return Res;
7133}
7134
7135template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007136StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7137 OMPParallelSectionsDirective *D) {
7138 DeclarationNameInfo DirName;
7139 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7140 nullptr, D->getLocStart());
7141 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7142 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7143 return Res;
7144}
7145
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007146template <typename Derived>
7147StmtResult
7148TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7149 DeclarationNameInfo DirName;
7150 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7151 D->getLocStart());
7152 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7153 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7154 return Res;
7155}
7156
Alexey Bataev68446b72014-07-18 07:47:19 +00007157template <typename Derived>
7158StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7159 OMPTaskyieldDirective *D) {
7160 DeclarationNameInfo DirName;
7161 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7162 D->getLocStart());
7163 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7164 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7165 return Res;
7166}
7167
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007168template <typename Derived>
7169StmtResult
7170TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7171 DeclarationNameInfo DirName;
7172 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7173 D->getLocStart());
7174 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7175 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7176 return Res;
7177}
7178
Alexey Bataev2df347a2014-07-18 10:17:07 +00007179template <typename Derived>
7180StmtResult
7181TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7182 DeclarationNameInfo DirName;
7183 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7184 D->getLocStart());
7185 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7186 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7187 return Res;
7188}
7189
Alexey Bataev6125da92014-07-21 11:26:11 +00007190template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007191StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7192 OMPTaskgroupDirective *D) {
7193 DeclarationNameInfo DirName;
7194 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7195 D->getLocStart());
7196 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7197 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7198 return Res;
7199}
7200
7201template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007202StmtResult
7203TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7204 DeclarationNameInfo DirName;
7205 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7206 D->getLocStart());
7207 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7209 return Res;
7210}
7211
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007212template <typename Derived>
7213StmtResult
7214TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7215 DeclarationNameInfo DirName;
7216 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7217 D->getLocStart());
7218 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7219 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7220 return Res;
7221}
7222
Alexey Bataev0162e452014-07-22 10:10:35 +00007223template <typename Derived>
7224StmtResult
7225TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7226 DeclarationNameInfo DirName;
7227 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7228 D->getLocStart());
7229 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7230 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7231 return Res;
7232}
7233
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007234template <typename Derived>
7235StmtResult
7236TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7237 DeclarationNameInfo DirName;
7238 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7239 D->getLocStart());
7240 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7241 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7242 return Res;
7243}
7244
Alexey Bataev13314bf2014-10-09 04:18:56 +00007245template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007246StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7247 OMPTargetDataDirective *D) {
7248 DeclarationNameInfo DirName;
7249 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7250 D->getLocStart());
7251 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7252 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7253 return Res;
7254}
7255
7256template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007257StmtResult
7258TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7259 DeclarationNameInfo DirName;
7260 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7261 D->getLocStart());
7262 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7263 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7264 return Res;
7265}
7266
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007267template <typename Derived>
7268StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7269 OMPCancellationPointDirective *D) {
7270 DeclarationNameInfo DirName;
7271 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7272 nullptr, D->getLocStart());
7273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7275 return Res;
7276}
7277
Alexey Bataev80909872015-07-02 11:25:17 +00007278template <typename Derived>
7279StmtResult
7280TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7281 DeclarationNameInfo DirName;
7282 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7283 D->getLocStart());
7284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7286 return Res;
7287}
7288
Alexander Musman64d33f12014-06-04 07:53:32 +00007289//===----------------------------------------------------------------------===//
7290// OpenMP clause transformation
7291//===----------------------------------------------------------------------===//
7292template <typename Derived>
7293OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007294 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7295 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007296 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007297 return getDerived().RebuildOMPIfClause(
7298 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7299 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007300}
7301
Alexander Musman64d33f12014-06-04 07:53:32 +00007302template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007303OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7304 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7305 if (Cond.isInvalid())
7306 return nullptr;
7307 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7308 C->getLParenLoc(), C->getLocEnd());
7309}
7310
7311template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007312OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007313TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7314 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7315 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007316 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007317 return getDerived().RebuildOMPNumThreadsClause(
7318 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007319}
7320
Alexey Bataev62c87d22014-03-21 04:51:18 +00007321template <typename Derived>
7322OMPClause *
7323TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7324 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7325 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007326 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007327 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007328 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007329}
7330
Alexander Musman8bd31e62014-05-27 15:12:19 +00007331template <typename Derived>
7332OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007333TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7334 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7335 if (E.isInvalid())
7336 return nullptr;
7337 return getDerived().RebuildOMPSimdlenClause(
7338 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7339}
7340
7341template <typename Derived>
7342OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007343TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7344 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7345 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007346 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007347 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007348 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007349}
7350
Alexander Musman64d33f12014-06-04 07:53:32 +00007351template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007352OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007353TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007354 return getDerived().RebuildOMPDefaultClause(
7355 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7356 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007357}
7358
Alexander Musman64d33f12014-06-04 07:53:32 +00007359template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007360OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007361TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007362 return getDerived().RebuildOMPProcBindClause(
7363 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7364 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007365}
7366
Alexander Musman64d33f12014-06-04 07:53:32 +00007367template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007368OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007369TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7370 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7371 if (E.isInvalid())
7372 return nullptr;
7373 return getDerived().RebuildOMPScheduleClause(
7374 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7375 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7376}
7377
7378template <typename Derived>
7379OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007380TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007381 ExprResult E;
7382 if (auto *Num = C->getNumForLoops()) {
7383 E = getDerived().TransformExpr(Num);
7384 if (E.isInvalid())
7385 return nullptr;
7386 }
7387 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7388 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007389}
7390
7391template <typename Derived>
7392OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007393TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7394 // No need to rebuild this clause, no template-dependent parameters.
7395 return C;
7396}
7397
7398template <typename Derived>
7399OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007400TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7401 // No need to rebuild this clause, no template-dependent parameters.
7402 return C;
7403}
7404
7405template <typename Derived>
7406OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007407TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7408 // No need to rebuild this clause, no template-dependent parameters.
7409 return C;
7410}
7411
7412template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007413OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7414 // No need to rebuild this clause, no template-dependent parameters.
7415 return C;
7416}
7417
7418template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007419OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7420 // No need to rebuild this clause, no template-dependent parameters.
7421 return C;
7422}
7423
7424template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007425OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007426TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7427 // No need to rebuild this clause, no template-dependent parameters.
7428 return C;
7429}
7430
7431template <typename Derived>
7432OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007433TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7434 // No need to rebuild this clause, no template-dependent parameters.
7435 return C;
7436}
7437
7438template <typename Derived>
7439OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007440TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7441 // No need to rebuild this clause, no template-dependent parameters.
7442 return C;
7443}
7444
7445template <typename Derived>
7446OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007447TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7448 // No need to rebuild this clause, no template-dependent parameters.
7449 return C;
7450}
7451
7452template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007453OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7454 // No need to rebuild this clause, no template-dependent parameters.
7455 return C;
7456}
7457
7458template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007459OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007460TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007461 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007462 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007463 for (auto *VE : C->varlists()) {
7464 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007465 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007466 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007467 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007468 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007469 return getDerived().RebuildOMPPrivateClause(
7470 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007471}
7472
Alexander Musman64d33f12014-06-04 07:53:32 +00007473template <typename Derived>
7474OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7475 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007476 llvm::SmallVector<Expr *, 16> Vars;
7477 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007478 for (auto *VE : C->varlists()) {
7479 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007480 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007481 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007482 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007483 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007484 return getDerived().RebuildOMPFirstprivateClause(
7485 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007486}
7487
Alexander Musman64d33f12014-06-04 07:53:32 +00007488template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007489OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007490TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7491 llvm::SmallVector<Expr *, 16> Vars;
7492 Vars.reserve(C->varlist_size());
7493 for (auto *VE : C->varlists()) {
7494 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7495 if (EVar.isInvalid())
7496 return nullptr;
7497 Vars.push_back(EVar.get());
7498 }
7499 return getDerived().RebuildOMPLastprivateClause(
7500 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7501}
7502
7503template <typename Derived>
7504OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007505TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7506 llvm::SmallVector<Expr *, 16> Vars;
7507 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007508 for (auto *VE : C->varlists()) {
7509 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007510 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007511 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007512 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007513 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007514 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7515 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007516}
7517
Alexander Musman64d33f12014-06-04 07:53:32 +00007518template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007519OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007520TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7521 llvm::SmallVector<Expr *, 16> Vars;
7522 Vars.reserve(C->varlist_size());
7523 for (auto *VE : C->varlists()) {
7524 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7525 if (EVar.isInvalid())
7526 return nullptr;
7527 Vars.push_back(EVar.get());
7528 }
7529 CXXScopeSpec ReductionIdScopeSpec;
7530 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7531
7532 DeclarationNameInfo NameInfo = C->getNameInfo();
7533 if (NameInfo.getName()) {
7534 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7535 if (!NameInfo.getName())
7536 return nullptr;
7537 }
7538 return getDerived().RebuildOMPReductionClause(
7539 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7540 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7541}
7542
7543template <typename Derived>
7544OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007545TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7546 llvm::SmallVector<Expr *, 16> Vars;
7547 Vars.reserve(C->varlist_size());
7548 for (auto *VE : C->varlists()) {
7549 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7550 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007551 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007552 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007553 }
7554 ExprResult Step = getDerived().TransformExpr(C->getStep());
7555 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007556 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007557 return getDerived().RebuildOMPLinearClause(
7558 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7559 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007560}
7561
Alexander Musman64d33f12014-06-04 07:53:32 +00007562template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007563OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007564TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7565 llvm::SmallVector<Expr *, 16> Vars;
7566 Vars.reserve(C->varlist_size());
7567 for (auto *VE : C->varlists()) {
7568 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7569 if (EVar.isInvalid())
7570 return nullptr;
7571 Vars.push_back(EVar.get());
7572 }
7573 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7574 if (Alignment.isInvalid())
7575 return nullptr;
7576 return getDerived().RebuildOMPAlignedClause(
7577 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7578 C->getColonLoc(), C->getLocEnd());
7579}
7580
Alexander Musman64d33f12014-06-04 07:53:32 +00007581template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007582OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007583TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7584 llvm::SmallVector<Expr *, 16> Vars;
7585 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007586 for (auto *VE : C->varlists()) {
7587 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007588 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007589 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007590 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007591 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007592 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7593 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007594}
7595
Alexey Bataevbae9a792014-06-27 10:37:06 +00007596template <typename Derived>
7597OMPClause *
7598TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7599 llvm::SmallVector<Expr *, 16> Vars;
7600 Vars.reserve(C->varlist_size());
7601 for (auto *VE : C->varlists()) {
7602 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7603 if (EVar.isInvalid())
7604 return nullptr;
7605 Vars.push_back(EVar.get());
7606 }
7607 return getDerived().RebuildOMPCopyprivateClause(
7608 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7609}
7610
Alexey Bataev6125da92014-07-21 11:26:11 +00007611template <typename Derived>
7612OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7613 llvm::SmallVector<Expr *, 16> Vars;
7614 Vars.reserve(C->varlist_size());
7615 for (auto *VE : C->varlists()) {
7616 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7617 if (EVar.isInvalid())
7618 return nullptr;
7619 Vars.push_back(EVar.get());
7620 }
7621 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7622 C->getLParenLoc(), C->getLocEnd());
7623}
7624
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007625template <typename Derived>
7626OMPClause *
7627TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7628 llvm::SmallVector<Expr *, 16> Vars;
7629 Vars.reserve(C->varlist_size());
7630 for (auto *VE : C->varlists()) {
7631 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7632 if (EVar.isInvalid())
7633 return nullptr;
7634 Vars.push_back(EVar.get());
7635 }
7636 return getDerived().RebuildOMPDependClause(
7637 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7638 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7639}
7640
Michael Wonge710d542015-08-07 16:16:36 +00007641template <typename Derived>
7642OMPClause *
7643TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7644 ExprResult E = getDerived().TransformExpr(C->getDevice());
7645 if (E.isInvalid())
7646 return nullptr;
7647 return getDerived().RebuildOMPDeviceClause(
7648 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7649}
7650
Douglas Gregorebe10102009-08-20 07:17:43 +00007651//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007652// Expression transformation
7653//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007656TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007657 if (!E->isTypeDependent())
7658 return E;
7659
7660 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7661 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007662}
Mike Stump11289f42009-09-09 15:08:12 +00007663
7664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007667 NestedNameSpecifierLoc QualifierLoc;
7668 if (E->getQualifierLoc()) {
7669 QualifierLoc
7670 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7671 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007672 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007673 }
John McCallce546572009-12-08 09:08:17 +00007674
7675 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007676 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7677 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007680
John McCall815039a2010-08-17 21:27:17 +00007681 DeclarationNameInfo NameInfo = E->getNameInfo();
7682 if (NameInfo.getName()) {
7683 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7684 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007685 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007686 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007687
7688 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007689 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007690 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007691 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007692 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007693
7694 // Mark it referenced in the new context regardless.
7695 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007696 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007697
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007698 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007699 }
John McCallce546572009-12-08 09:08:17 +00007700
Craig Topperc3ec1492014-05-26 06:22:03 +00007701 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007702 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007703 TemplateArgs = &TransArgs;
7704 TransArgs.setLAngleLoc(E->getLAngleLoc());
7705 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007706 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7707 E->getNumTemplateArgs(),
7708 TransArgs))
7709 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007710 }
7711
Chad Rosier1dcde962012-08-08 18:46:20 +00007712 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007713 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007714}
Mike Stump11289f42009-09-09 15:08:12 +00007715
Douglas Gregora16548e2009-08-11 05:31:07 +00007716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007718TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007719 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007720}
Mike Stump11289f42009-09-09 15:08:12 +00007721
Douglas Gregora16548e2009-08-11 05:31:07 +00007722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007724TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007725 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007726}
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007730TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007731 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007732}
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregora16548e2009-08-11 05:31:07 +00007734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007736TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007737 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007738}
Mike Stump11289f42009-09-09 15:08:12 +00007739
Douglas Gregora16548e2009-08-11 05:31:07 +00007740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007742TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007743 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007744}
7745
7746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007747ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007748TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007749 if (FunctionDecl *FD = E->getDirectCallee())
7750 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007751 return SemaRef.MaybeBindToTemporary(E);
7752}
7753
7754template<typename Derived>
7755ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007756TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7757 ExprResult ControllingExpr =
7758 getDerived().TransformExpr(E->getControllingExpr());
7759 if (ControllingExpr.isInvalid())
7760 return ExprError();
7761
Chris Lattner01cf8db2011-07-20 06:58:45 +00007762 SmallVector<Expr *, 4> AssocExprs;
7763 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007764 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7765 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7766 if (TS) {
7767 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7768 if (!AssocType)
7769 return ExprError();
7770 AssocTypes.push_back(AssocType);
7771 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007772 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007773 }
7774
7775 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7776 if (AssocExpr.isInvalid())
7777 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007778 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007779 }
7780
7781 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7782 E->getDefaultLoc(),
7783 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007784 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007785 AssocTypes,
7786 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007787}
7788
7789template<typename Derived>
7790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007791TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007792 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007793 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007795
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007797 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007798
John McCallb268a282010-08-23 23:25:46 +00007799 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007800 E->getRParen());
7801}
7802
Richard Smithdb2630f2012-10-21 03:28:35 +00007803/// \brief The operand of a unary address-of operator has special rules: it's
7804/// allowed to refer to a non-static member of a class even if there's no 'this'
7805/// object available.
7806template<typename Derived>
7807ExprResult
7808TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7809 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007810 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007811 else
7812 return getDerived().TransformExpr(E);
7813}
7814
Mike Stump11289f42009-09-09 15:08:12 +00007815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007817TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007818 ExprResult SubExpr;
7819 if (E->getOpcode() == UO_AddrOf)
7820 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7821 else
7822 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007827 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007828
Douglas Gregora16548e2009-08-11 05:31:07 +00007829 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7830 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007831 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007832}
Mike Stump11289f42009-09-09 15:08:12 +00007833
Douglas Gregora16548e2009-08-11 05:31:07 +00007834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007835ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007836TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7837 // Transform the type.
7838 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7839 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007840 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007841
Douglas Gregor882211c2010-04-28 22:16:22 +00007842 // Transform all of the components into components similar to what the
7843 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007844 // FIXME: It would be slightly more efficient in the non-dependent case to
7845 // just map FieldDecls, rather than requiring the rebuilder to look for
7846 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007847 // template code that we don't care.
7848 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007849 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007850 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007851 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007852 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7853 const Node &ON = E->getComponent(I);
7854 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007855 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007856 Comp.LocStart = ON.getSourceRange().getBegin();
7857 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007858 switch (ON.getKind()) {
7859 case Node::Array: {
7860 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007861 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007862 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007864
Douglas Gregor882211c2010-04-28 22:16:22 +00007865 ExprChanged = ExprChanged || Index.get() != FromIndex;
7866 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007867 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007868 break;
7869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007870
Douglas Gregor882211c2010-04-28 22:16:22 +00007871 case Node::Field:
7872 case Node::Identifier:
7873 Comp.isBrackets = false;
7874 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007875 if (!Comp.U.IdentInfo)
7876 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007877
Douglas Gregor882211c2010-04-28 22:16:22 +00007878 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007879
Douglas Gregord1702062010-04-29 00:18:15 +00007880 case Node::Base:
7881 // Will be recomputed during the rebuild.
7882 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007884
Douglas Gregor882211c2010-04-28 22:16:22 +00007885 Components.push_back(Comp);
7886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007887
Douglas Gregor882211c2010-04-28 22:16:22 +00007888 // If nothing changed, retain the existing expression.
7889 if (!getDerived().AlwaysRebuild() &&
7890 Type == E->getTypeSourceInfo() &&
7891 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007892 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007893
Douglas Gregor882211c2010-04-28 22:16:22 +00007894 // Build a new offsetof expression.
7895 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00007896 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00007897}
7898
7899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007900ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007901TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00007902 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00007903 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007904 return E;
John McCall8d69a212010-11-15 23:31:06 +00007905}
7906
7907template<typename Derived>
7908ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007909TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7910 return E;
7911}
7912
7913template<typename Derived>
7914ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007915TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007916 // Rebuild the syntactic form. The original syntactic form has
7917 // opaque-value expressions in it, so strip those away and rebuild
7918 // the result. This is a really awful way of doing this, but the
7919 // better solution (rebuilding the semantic expressions and
7920 // rebinding OVEs as necessary) doesn't work; we'd need
7921 // TreeTransform to not strip away implicit conversions.
7922 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7923 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007924 if (result.isInvalid()) return ExprError();
7925
7926 // If that gives us a pseudo-object result back, the pseudo-object
7927 // expression must have been an lvalue-to-rvalue conversion which we
7928 // should reapply.
7929 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007930 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007931
7932 return result;
7933}
7934
7935template<typename Derived>
7936ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007937TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7938 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007940 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007941
John McCallbcd03502009-12-07 02:54:59 +00007942 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007943 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007945
John McCall4c98fd82009-11-04 07:28:41 +00007946 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007947 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007948
Peter Collingbournee190dee2011-03-11 19:24:49 +00007949 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7950 E->getKind(),
7951 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007952 }
Mike Stump11289f42009-09-09 15:08:12 +00007953
Eli Friedmane4f22df2012-02-29 04:03:55 +00007954 // C++0x [expr.sizeof]p1:
7955 // The operand is either an expression, which is an unevaluated operand
7956 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007957 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7958 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007959
Reid Kleckner32506ed2014-06-12 23:03:48 +00007960 // Try to recover if we have something like sizeof(T::X) where X is a type.
7961 // Notably, there must be *exactly* one set of parens if X is a type.
7962 TypeSourceInfo *RecoveryTSI = nullptr;
7963 ExprResult SubExpr;
7964 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7965 if (auto *DRE =
7966 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7967 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7968 PE, DRE, false, &RecoveryTSI);
7969 else
7970 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7971
7972 if (RecoveryTSI) {
7973 return getDerived().RebuildUnaryExprOrTypeTrait(
7974 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7975 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007977
Eli Friedmane4f22df2012-02-29 04:03:55 +00007978 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007979 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007980
Peter Collingbournee190dee2011-03-11 19:24:49 +00007981 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7982 E->getOperatorLoc(),
7983 E->getKind(),
7984 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007985}
Mike Stump11289f42009-09-09 15:08:12 +00007986
Douglas Gregora16548e2009-08-11 05:31:07 +00007987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007989TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007990 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007993
John McCalldadc5752010-08-24 06:29:42 +00007994 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007997
7998
Douglas Gregora16548e2009-08-11 05:31:07 +00007999 if (!getDerived().AlwaysRebuild() &&
8000 LHS.get() == E->getLHS() &&
8001 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008002 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008003
John McCallb268a282010-08-23 23:25:46 +00008004 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008006 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008007 E->getRBracketLoc());
8008}
Mike Stump11289f42009-09-09 15:08:12 +00008009
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008010template <typename Derived>
8011ExprResult
8012TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8013 ExprResult Base = getDerived().TransformExpr(E->getBase());
8014 if (Base.isInvalid())
8015 return ExprError();
8016
8017 ExprResult LowerBound;
8018 if (E->getLowerBound()) {
8019 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8020 if (LowerBound.isInvalid())
8021 return ExprError();
8022 }
8023
8024 ExprResult Length;
8025 if (E->getLength()) {
8026 Length = getDerived().TransformExpr(E->getLength());
8027 if (Length.isInvalid())
8028 return ExprError();
8029 }
8030
8031 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8032 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8033 return E;
8034
8035 return getDerived().RebuildOMPArraySectionExpr(
8036 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8037 Length.get(), E->getRBracketLoc());
8038}
8039
Mike Stump11289f42009-09-09 15:08:12 +00008040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008042TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008044 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008045 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008046 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008047
8048 // Transform arguments.
8049 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008050 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008051 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008052 &ArgChanged))
8053 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008054
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (!getDerived().AlwaysRebuild() &&
8056 Callee.get() == E->getCallee() &&
8057 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008058 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008059
Douglas Gregora16548e2009-08-11 05:31:07 +00008060 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008061 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008062 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008063 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008064 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008065 E->getRParenLoc());
8066}
Mike Stump11289f42009-09-09 15:08:12 +00008067
8068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008070TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008071 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008072 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008073 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008074
Douglas Gregorea972d32011-02-28 21:54:11 +00008075 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008076 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008077 QualifierLoc
8078 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008079
Douglas Gregorea972d32011-02-28 21:54:11 +00008080 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008082 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008083 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008084
Eli Friedman2cfcef62009-12-04 06:40:45 +00008085 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008086 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8087 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008088 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008089 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008090
John McCall16df1e52010-03-30 21:47:33 +00008091 NamedDecl *FoundDecl = E->getFoundDecl();
8092 if (FoundDecl == E->getMemberDecl()) {
8093 FoundDecl = Member;
8094 } else {
8095 FoundDecl = cast_or_null<NamedDecl>(
8096 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8097 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008098 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008099 }
8100
Douglas Gregora16548e2009-08-11 05:31:07 +00008101 if (!getDerived().AlwaysRebuild() &&
8102 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008103 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008104 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008105 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008106 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008107
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008108 // Mark it referenced in the new context regardless.
8109 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008110 SemaRef.MarkMemberReferenced(E);
8111
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008112 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008113 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008114
John McCall6b51f282009-11-23 01:53:49 +00008115 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008116 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008117 TransArgs.setLAngleLoc(E->getLAngleLoc());
8118 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008119 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8120 E->getNumTemplateArgs(),
8121 TransArgs))
8122 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008124
Douglas Gregora16548e2009-08-11 05:31:07 +00008125 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008126 SourceLocation FakeOperatorLoc =
8127 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008128
John McCall38836f02010-01-15 08:34:02 +00008129 // FIXME: to do this check properly, we will need to preserve the
8130 // first-qualifier-in-scope here, just in case we had a dependent
8131 // base (and therefore couldn't do the check) and a
8132 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008133 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008134
John McCallb268a282010-08-23 23:25:46 +00008135 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008136 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008137 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008138 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008139 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008140 Member,
John McCall16df1e52010-03-30 21:47:33 +00008141 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008142 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008143 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008144 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008145}
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregora16548e2009-08-11 05:31:07 +00008147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008149TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008150 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008153
John McCalldadc5752010-08-24 06:29:42 +00008154 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008157
Douglas Gregora16548e2009-08-11 05:31:07 +00008158 if (!getDerived().AlwaysRebuild() &&
8159 LHS.get() == E->getLHS() &&
8160 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008161 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008162
Lang Hames5de91cc2012-10-02 04:45:10 +00008163 Sema::FPContractStateRAII FPContractState(getSema());
8164 getSema().FPFeatures.fp_contract = E->isFPContractable();
8165
Douglas Gregora16548e2009-08-11 05:31:07 +00008166 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008167 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008168}
8169
Mike Stump11289f42009-09-09 15:08:12 +00008170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008171ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008172TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008173 CompoundAssignOperator *E) {
8174 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008175}
Mike Stump11289f42009-09-09 15:08:12 +00008176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008178ExprResult TreeTransform<Derived>::
8179TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8180 // Just rebuild the common and RHS expressions and see whether we
8181 // get any changes.
8182
8183 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8184 if (commonExpr.isInvalid())
8185 return ExprError();
8186
8187 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8188 if (rhs.isInvalid())
8189 return ExprError();
8190
8191 if (!getDerived().AlwaysRebuild() &&
8192 commonExpr.get() == e->getCommon() &&
8193 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008194 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008195
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008196 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008197 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008198 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008199 e->getColonLoc(),
8200 rhs.get());
8201}
8202
8203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008205TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008206 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008207 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008209
John McCalldadc5752010-08-24 06:29:42 +00008210 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008211 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008213
John McCalldadc5752010-08-24 06:29:42 +00008214 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008215 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218 if (!getDerived().AlwaysRebuild() &&
8219 Cond.get() == E->getCond() &&
8220 LHS.get() == E->getLHS() &&
8221 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008222 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008223
John McCallb268a282010-08-23 23:25:46 +00008224 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008225 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008226 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008227 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008228 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
8231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008233TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008234 // Implicit casts are eliminated during transformation, since they
8235 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008236 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008237}
Mike Stump11289f42009-09-09 15:08:12 +00008238
Douglas Gregora16548e2009-08-11 05:31:07 +00008239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008241TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008242 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8243 if (!Type)
8244 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008245
John McCalldadc5752010-08-24 06:29:42 +00008246 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008247 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregora16548e2009-08-11 05:31:07 +00008251 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008252 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008253 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008254 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008255
John McCall97513962010-01-15 18:39:57 +00008256 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008257 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008258 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008259 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008260}
Mike Stump11289f42009-09-09 15:08:12 +00008261
Douglas Gregora16548e2009-08-11 05:31:07 +00008262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008264TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008265 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8266 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8267 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008269
John McCalldadc5752010-08-24 06:29:42 +00008270 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008275 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008277 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008278
John McCall5d7aa7f2010-01-19 22:33:45 +00008279 // Note: the expression type doesn't necessarily match the
8280 // type-as-written, but that's okay, because it should always be
8281 // derivable from the initializer.
8282
John McCalle15bbff2010-01-18 19:35:47 +00008283 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008285 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008286}
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregora16548e2009-08-11 05:31:07 +00008288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008290TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008291 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008292 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008294
Douglas Gregora16548e2009-08-11 05:31:07 +00008295 if (!getDerived().AlwaysRebuild() &&
8296 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008297 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008298
Douglas Gregora16548e2009-08-11 05:31:07 +00008299 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008300 SourceLocation FakeOperatorLoc =
8301 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008302 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008303 E->getAccessorLoc(),
8304 E->getAccessor());
8305}
Mike Stump11289f42009-09-09 15:08:12 +00008306
Douglas Gregora16548e2009-08-11 05:31:07 +00008307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008309TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008310 if (InitListExpr *Syntactic = E->getSyntacticForm())
8311 E = Syntactic;
8312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008314
Benjamin Kramerf0623432012-08-23 22:51:59 +00008315 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008316 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008317 Inits, &InitChanged))
8318 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008319
Richard Smith520449d2015-02-05 06:15:50 +00008320 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8321 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8322 // in some cases. We can't reuse it in general, because the syntactic and
8323 // semantic forms are linked, and we can't know that semantic form will
8324 // match even if the syntactic form does.
8325 }
Mike Stump11289f42009-09-09 15:08:12 +00008326
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008327 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008328 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008329}
Mike Stump11289f42009-09-09 15:08:12 +00008330
Douglas Gregora16548e2009-08-11 05:31:07 +00008331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008333TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008334 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregorebe10102009-08-20 07:17:43 +00008336 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008337 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008338 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008340
Douglas Gregorebe10102009-08-20 07:17:43 +00008341 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008342 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 bool ExprChanged = false;
8344 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8345 DEnd = E->designators_end();
8346 D != DEnd; ++D) {
8347 if (D->isFieldDesignator()) {
8348 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8349 D->getDotLoc(),
8350 D->getFieldLoc()));
8351 continue;
8352 }
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008355 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008356 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008357 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008358
8359 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008360 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008361
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008363 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008364 continue;
8365 }
Mike Stump11289f42009-09-09 15:08:12 +00008366
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008368 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8370 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008372
John McCalldadc5752010-08-24 06:29:42 +00008373 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008376
8377 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008378 End.get(),
8379 D->getLBracketLoc(),
8380 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008381
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8383 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008384
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008385 ArrayExprs.push_back(Start.get());
8386 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008387 }
Mike Stump11289f42009-09-09 15:08:12 +00008388
Douglas Gregora16548e2009-08-11 05:31:07 +00008389 if (!getDerived().AlwaysRebuild() &&
8390 Init.get() == E->getInit() &&
8391 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008392 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008393
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008394 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008395 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008396 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008397}
Mike Stump11289f42009-09-09 15:08:12 +00008398
Yunzhong Gaocb779302015-06-10 00:27:52 +00008399// Seems that if TransformInitListExpr() only works on the syntactic form of an
8400// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8401template<typename Derived>
8402ExprResult
8403TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8404 DesignatedInitUpdateExpr *E) {
8405 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8406 "initializer");
8407 return ExprError();
8408}
8409
8410template<typename Derived>
8411ExprResult
8412TreeTransform<Derived>::TransformNoInitExpr(
8413 NoInitExpr *E) {
8414 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8415 return ExprError();
8416}
8417
Douglas Gregora16548e2009-08-11 05:31:07 +00008418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008419ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008420TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008421 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008422 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008423
Douglas Gregor3da3c062009-10-28 00:29:27 +00008424 // FIXME: Will we ever have proper type location here? Will we actually
8425 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 QualType T = getDerived().TransformType(E->getType());
8427 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008429
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 if (!getDerived().AlwaysRebuild() &&
8431 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 return getDerived().RebuildImplicitValueInitExpr(T);
8435}
Mike Stump11289f42009-09-09 15:08:12 +00008436
Douglas Gregora16548e2009-08-11 05:31:07 +00008437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008439TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008440 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8441 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008443
John McCalldadc5752010-08-24 06:29:42 +00008444 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008445 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008449 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008450 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008451 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008452
John McCallb268a282010-08-23 23:25:46 +00008453 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008454 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008455}
8456
8457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008459TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008460 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008461 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008462 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8463 &ArgumentChanged))
8464 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008465
Douglas Gregora16548e2009-08-11 05:31:07 +00008466 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008467 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008468 E->getRParenLoc());
8469}
Mike Stump11289f42009-09-09 15:08:12 +00008470
Douglas Gregora16548e2009-08-11 05:31:07 +00008471/// \brief Transform an address-of-label expression.
8472///
8473/// By default, the transformation of an address-of-label expression always
8474/// rebuilds the expression, so that the label identifier can be resolved to
8475/// the corresponding label statement by semantic analysis.
8476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008478TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008479 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8480 E->getLabel());
8481 if (!LD)
8482 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008483
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008485 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008486}
Mike Stump11289f42009-09-09 15:08:12 +00008487
8488template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008490TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008491 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008492 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008493 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008494 if (SubStmt.isInvalid()) {
8495 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008496 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008497 }
Mike Stump11289f42009-09-09 15:08:12 +00008498
Douglas Gregora16548e2009-08-11 05:31:07 +00008499 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008500 SubStmt.get() == E->getSubStmt()) {
8501 // Calling this an 'error' is unintuitive, but it does the right thing.
8502 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008503 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008504 }
Mike Stump11289f42009-09-09 15:08:12 +00008505
8506 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008507 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008508 E->getRParenLoc());
8509}
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008513TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008514 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008517
John McCalldadc5752010-08-24 06:29:42 +00008518 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008521
John McCalldadc5752010-08-24 06:29:42 +00008522 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008523 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 if (!getDerived().AlwaysRebuild() &&
8527 Cond.get() == E->getCond() &&
8528 LHS.get() == E->getLHS() &&
8529 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008530 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008531
Douglas Gregora16548e2009-08-11 05:31:07 +00008532 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008533 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 E->getRParenLoc());
8535}
Mike Stump11289f42009-09-09 15:08:12 +00008536
Douglas Gregora16548e2009-08-11 05:31:07 +00008537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008539TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008540 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008541}
8542
8543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008545TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008546 switch (E->getOperator()) {
8547 case OO_New:
8548 case OO_Delete:
8549 case OO_Array_New:
8550 case OO_Array_Delete:
8551 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008552
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008553 case OO_Call: {
8554 // This is a call to an object's operator().
8555 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8556
8557 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008558 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008559 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008560 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008561
8562 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008563 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8564 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008565
8566 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008567 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008568 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008569 Args))
8570 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008571
John McCallb268a282010-08-23 23:25:46 +00008572 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008573 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008574 E->getLocEnd());
8575 }
8576
8577#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8578 case OO_##Name:
8579#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8580#include "clang/Basic/OperatorKinds.def"
8581 case OO_Subscript:
8582 // Handled below.
8583 break;
8584
8585 case OO_Conditional:
8586 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008587
8588 case OO_None:
8589 case NUM_OVERLOADED_OPERATORS:
8590 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008591 }
8592
John McCalldadc5752010-08-24 06:29:42 +00008593 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008596
Richard Smithdb2630f2012-10-21 03:28:35 +00008597 ExprResult First;
8598 if (E->getOperator() == OO_Amp)
8599 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8600 else
8601 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008602 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008603 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008604
John McCalldadc5752010-08-24 06:29:42 +00008605 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008606 if (E->getNumArgs() == 2) {
8607 Second = getDerived().TransformExpr(E->getArg(1));
8608 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008609 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008610 }
Mike Stump11289f42009-09-09 15:08:12 +00008611
Douglas Gregora16548e2009-08-11 05:31:07 +00008612 if (!getDerived().AlwaysRebuild() &&
8613 Callee.get() == E->getCallee() &&
8614 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008615 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008616 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008617
Lang Hames5de91cc2012-10-02 04:45:10 +00008618 Sema::FPContractStateRAII FPContractState(getSema());
8619 getSema().FPFeatures.fp_contract = E->isFPContractable();
8620
Douglas Gregora16548e2009-08-11 05:31:07 +00008621 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8622 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008623 Callee.get(),
8624 First.get(),
8625 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008626}
Mike Stump11289f42009-09-09 15:08:12 +00008627
Douglas Gregora16548e2009-08-11 05:31:07 +00008628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008630TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8631 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008632}
Mike Stump11289f42009-09-09 15:08:12 +00008633
Douglas Gregora16548e2009-08-11 05:31:07 +00008634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008635ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008636TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8637 // Transform the callee.
8638 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8639 if (Callee.isInvalid())
8640 return ExprError();
8641
8642 // Transform exec config.
8643 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8644 if (EC.isInvalid())
8645 return ExprError();
8646
8647 // Transform arguments.
8648 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008649 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008650 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008651 &ArgChanged))
8652 return ExprError();
8653
8654 if (!getDerived().AlwaysRebuild() &&
8655 Callee.get() == E->getCallee() &&
8656 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008657 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008658
8659 // FIXME: Wrong source location information for the '('.
8660 SourceLocation FakeLParenLoc
8661 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8662 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008663 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008664 E->getRParenLoc(), EC.get());
8665}
8666
8667template<typename Derived>
8668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008669TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008670 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8671 if (!Type)
8672 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008673
John McCalldadc5752010-08-24 06:29:42 +00008674 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008675 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008676 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008678
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008680 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008681 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008682 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008683 return getDerived().RebuildCXXNamedCastExpr(
8684 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8685 Type, E->getAngleBrackets().getEnd(),
8686 // FIXME. this should be '(' location
8687 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008688}
Mike Stump11289f42009-09-09 15:08:12 +00008689
Douglas Gregora16548e2009-08-11 05:31:07 +00008690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8693 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008694}
Mike Stump11289f42009-09-09 15:08:12 +00008695
8696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008697ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008698TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8699 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008700}
8701
Douglas Gregora16548e2009-08-11 05:31:07 +00008702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008703ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008704TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008705 CXXReinterpretCastExpr *E) {
8706 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008707}
Mike Stump11289f42009-09-09 15:08:12 +00008708
Douglas Gregora16548e2009-08-11 05:31:07 +00008709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008710ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008711TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8712 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008713}
Mike Stump11289f42009-09-09 15:08:12 +00008714
Douglas Gregora16548e2009-08-11 05:31:07 +00008715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008716ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008717TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008718 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008719 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8720 if (!Type)
8721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008722
John McCalldadc5752010-08-24 06:29:42 +00008723 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008724 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008725 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008727
Douglas Gregora16548e2009-08-11 05:31:07 +00008728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008729 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008730 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008731 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008732
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008733 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008734 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008735 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008736 E->getRParenLoc());
8737}
Mike Stump11289f42009-09-09 15:08:12 +00008738
Douglas Gregora16548e2009-08-11 05:31:07 +00008739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008741TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008743 TypeSourceInfo *TInfo
8744 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8745 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008747
Douglas Gregora16548e2009-08-11 05:31:07 +00008748 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008749 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008750 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregor9da64192010-04-26 22:37:10 +00008752 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8753 E->getLocStart(),
8754 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008755 E->getLocEnd());
8756 }
Mike Stump11289f42009-09-09 15:08:12 +00008757
Eli Friedman456f0182012-01-20 01:26:23 +00008758 // We don't know whether the subexpression is potentially evaluated until
8759 // after we perform semantic analysis. We speculatively assume it is
8760 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008761 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008762 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8763 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008764
John McCalldadc5752010-08-24 06:29:42 +00008765 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008766 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008768
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 if (!getDerived().AlwaysRebuild() &&
8770 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008771 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008772
Douglas Gregor9da64192010-04-26 22:37:10 +00008773 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8774 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008775 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008776 E->getLocEnd());
8777}
8778
8779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008780ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008781TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8782 if (E->isTypeOperand()) {
8783 TypeSourceInfo *TInfo
8784 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8785 if (!TInfo)
8786 return ExprError();
8787
8788 if (!getDerived().AlwaysRebuild() &&
8789 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008790 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008791
Douglas Gregor69735112011-03-06 17:40:41 +00008792 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008793 E->getLocStart(),
8794 TInfo,
8795 E->getLocEnd());
8796 }
8797
Francois Pichet9f4f2072010-09-08 12:20:18 +00008798 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8799
8800 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8801 if (SubExpr.isInvalid())
8802 return ExprError();
8803
8804 if (!getDerived().AlwaysRebuild() &&
8805 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008807
8808 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8809 E->getLocStart(),
8810 SubExpr.get(),
8811 E->getLocEnd());
8812}
8813
8814template<typename Derived>
8815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008816TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008817 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008818}
Mike Stump11289f42009-09-09 15:08:12 +00008819
Douglas Gregora16548e2009-08-11 05:31:07 +00008820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008821ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008822TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008823 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008824 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008825}
Mike Stump11289f42009-09-09 15:08:12 +00008826
Douglas Gregora16548e2009-08-11 05:31:07 +00008827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008829TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008830 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008831
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008832 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8833 // Make sure that we capture 'this'.
8834 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008835 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008837
Douglas Gregorb15af892010-01-07 23:12:05 +00008838 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008839}
Mike Stump11289f42009-09-09 15:08:12 +00008840
Douglas Gregora16548e2009-08-11 05:31:07 +00008841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008843TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008844 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008845 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008847
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 if (!getDerived().AlwaysRebuild() &&
8849 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008850 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008851
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008852 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8853 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008854}
Mike Stump11289f42009-09-09 15:08:12 +00008855
Douglas Gregora16548e2009-08-11 05:31:07 +00008856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008858TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008859 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008860 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8861 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008862 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008864
Chandler Carruth794da4c2010-02-08 06:42:49 +00008865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008866 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008867 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008868
Douglas Gregor033f6752009-12-23 23:03:06 +00008869 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008870}
Mike Stump11289f42009-09-09 15:08:12 +00008871
Douglas Gregora16548e2009-08-11 05:31:07 +00008872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008873ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008874TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8875 FieldDecl *Field
8876 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8877 E->getField()));
8878 if (!Field)
8879 return ExprError();
8880
8881 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008882 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008883
8884 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8885}
8886
8887template<typename Derived>
8888ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008889TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8890 CXXScalarValueInitExpr *E) {
8891 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8892 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008893 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008894
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008896 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008897 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008898
Chad Rosier1dcde962012-08-08 18:46:20 +00008899 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008900 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008901 E->getRParenLoc());
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>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008907 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008908 TypeSourceInfo *AllocTypeInfo
8909 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8910 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008912
Douglas Gregora16548e2009-08-11 05:31:07 +00008913 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008914 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008915 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008917
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 // Transform the placement arguments (if any).
8919 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008920 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008921 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008922 E->getNumPlacementArgs(), true,
8923 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008924 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008925
Sebastian Redl6047f072012-02-16 12:22:20 +00008926 // Transform the initializer (if any).
8927 Expr *OldInit = E->getInitializer();
8928 ExprResult NewInit;
8929 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008930 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008931 if (NewInit.isInvalid())
8932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008933
Sebastian Redl6047f072012-02-16 12:22:20 +00008934 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008935 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008936 if (E->getOperatorNew()) {
8937 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008938 getDerived().TransformDecl(E->getLocStart(),
8939 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008940 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008941 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008942 }
8943
Craig Topperc3ec1492014-05-26 06:22:03 +00008944 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008945 if (E->getOperatorDelete()) {
8946 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008947 getDerived().TransformDecl(E->getLocStart(),
8948 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008949 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008950 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008951 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008952
Douglas Gregora16548e2009-08-11 05:31:07 +00008953 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008954 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008956 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008957 OperatorNew == E->getOperatorNew() &&
8958 OperatorDelete == E->getOperatorDelete() &&
8959 !ArgumentChanged) {
8960 // Mark any declarations we need as referenced.
8961 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008962 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008963 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008964 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008965 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008966
Sebastian Redl6047f072012-02-16 12:22:20 +00008967 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008968 QualType ElementType
8969 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8970 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8971 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8972 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008973 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008974 }
8975 }
8976 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008977
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008978 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008979 }
Mike Stump11289f42009-09-09 15:08:12 +00008980
Douglas Gregor0744ef62010-09-07 21:49:58 +00008981 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008982 if (!ArraySize.get()) {
8983 // If no array size was specified, but the new expression was
8984 // instantiated with an array type (e.g., "new T" where T is
8985 // instantiated with "int[4]"), extract the outer bound from the
8986 // array type as our array size. We do this with constant and
8987 // dependently-sized array types.
8988 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8989 if (!ArrayT) {
8990 // Do nothing
8991 } else if (const ConstantArrayType *ConsArrayT
8992 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008993 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8994 SemaRef.Context.getSizeType(),
8995 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008996 AllocType = ConsArrayT->getElementType();
8997 } else if (const DependentSizedArrayType *DepArrayT
8998 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8999 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009000 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009001 AllocType = DepArrayT->getElementType();
9002 }
9003 }
9004 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009005
Douglas Gregora16548e2009-08-11 05:31:07 +00009006 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9007 E->isGlobalNew(),
9008 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009009 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009010 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009011 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009012 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009013 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009014 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009015 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009016 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009017}
Mike Stump11289f42009-09-09 15:08:12 +00009018
Douglas Gregora16548e2009-08-11 05:31:07 +00009019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009021TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009022 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009023 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009025
Douglas Gregord2d9da02010-02-26 00:38:10 +00009026 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009027 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009028 if (E->getOperatorDelete()) {
9029 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009030 getDerived().TransformDecl(E->getLocStart(),
9031 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009032 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009033 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009035
Douglas Gregora16548e2009-08-11 05:31:07 +00009036 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009037 Operand.get() == E->getArgument() &&
9038 OperatorDelete == E->getOperatorDelete()) {
9039 // Mark any declarations we need as referenced.
9040 // FIXME: instantiation-specific.
9041 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009042 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009043
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009044 if (!E->getArgument()->isTypeDependent()) {
9045 QualType Destroyed = SemaRef.Context.getBaseElementType(
9046 E->getDestroyedType());
9047 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9048 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009049 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009050 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009051 }
9052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009054 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009055 }
Mike Stump11289f42009-09-09 15:08:12 +00009056
Douglas Gregora16548e2009-08-11 05:31:07 +00009057 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9058 E->isGlobalDelete(),
9059 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009060 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009061}
Mike Stump11289f42009-09-09 15:08:12 +00009062
Douglas Gregora16548e2009-08-11 05:31:07 +00009063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009064ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009065TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009066 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009067 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009068 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009070
John McCallba7bf592010-08-24 05:47:05 +00009071 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009072 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009073 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009074 E->getOperatorLoc(),
9075 E->isArrow()? tok::arrow : tok::period,
9076 ObjectTypePtr,
9077 MayBePseudoDestructor);
9078 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009079 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009080
John McCallba7bf592010-08-24 05:47:05 +00009081 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009082 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9083 if (QualifierLoc) {
9084 QualifierLoc
9085 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9086 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009087 return ExprError();
9088 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009089 CXXScopeSpec SS;
9090 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009091
Douglas Gregor678f90d2010-02-25 01:56:36 +00009092 PseudoDestructorTypeStorage Destroyed;
9093 if (E->getDestroyedTypeInfo()) {
9094 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009095 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009096 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009097 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009098 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009099 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009100 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009101 // We aren't likely to be able to resolve the identifier down to a type
9102 // now anyway, so just retain the identifier.
9103 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9104 E->getDestroyedTypeLoc());
9105 } else {
9106 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009107 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009108 *E->getDestroyedTypeIdentifier(),
9109 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009110 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009111 SS, ObjectTypePtr,
9112 false);
9113 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009114 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregor678f90d2010-02-25 01:56:36 +00009116 Destroyed
9117 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9118 E->getDestroyedTypeLoc());
9119 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009120
Craig Topperc3ec1492014-05-26 06:22:03 +00009121 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009122 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009123 CXXScopeSpec EmptySS;
9124 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009125 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009126 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009127 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009129
John McCallb268a282010-08-23 23:25:46 +00009130 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009131 E->getOperatorLoc(),
9132 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009133 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009134 ScopeTypeInfo,
9135 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009136 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009137 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009138}
Mike Stump11289f42009-09-09 15:08:12 +00009139
Douglas Gregorad8a3362009-09-04 17:36:40 +00009140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009141ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009142TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009143 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009144 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9145 Sema::LookupOrdinaryName);
9146
9147 // Transform all the decls.
9148 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9149 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009150 NamedDecl *InstD = static_cast<NamedDecl*>(
9151 getDerived().TransformDecl(Old->getNameLoc(),
9152 *I));
John McCall84d87672009-12-10 09:41:52 +00009153 if (!InstD) {
9154 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9155 // This can happen because of dependent hiding.
9156 if (isa<UsingShadowDecl>(*I))
9157 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009158 else {
9159 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009160 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009161 }
John McCall84d87672009-12-10 09:41:52 +00009162 }
John McCalle66edc12009-11-24 19:00:30 +00009163
9164 // Expand using declarations.
9165 if (isa<UsingDecl>(InstD)) {
9166 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009167 for (auto *I : UD->shadows())
9168 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009169 continue;
9170 }
9171
9172 R.addDecl(InstD);
9173 }
9174
9175 // Resolve a kind, but don't do any further analysis. If it's
9176 // ambiguous, the callee needs to deal with it.
9177 R.resolveKind();
9178
9179 // Rebuild the nested-name qualifier, if present.
9180 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009181 if (Old->getQualifierLoc()) {
9182 NestedNameSpecifierLoc QualifierLoc
9183 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9184 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009185 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009186
Douglas Gregor0da1d432011-02-28 20:01:57 +00009187 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009188 }
9189
Douglas Gregor9262f472010-04-27 18:19:34 +00009190 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009191 CXXRecordDecl *NamingClass
9192 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9193 Old->getNameLoc(),
9194 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009195 if (!NamingClass) {
9196 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009197 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
Douglas Gregorda7be082010-04-27 16:10:10 +00009200 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009201 }
9202
Abramo Bagnara7945c982012-01-27 09:46:47 +00009203 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9204
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009205 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009206 // it's a normal declaration name or member reference.
9207 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9208 NamedDecl *D = R.getAsSingle<NamedDecl>();
9209 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9210 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9211 // give a good diagnostic.
9212 if (D && D->isCXXInstanceMember()) {
9213 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9214 /*TemplateArgs=*/nullptr,
9215 /*Scope=*/nullptr);
9216 }
9217
John McCalle66edc12009-11-24 19:00:30 +00009218 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009219 }
John McCalle66edc12009-11-24 19:00:30 +00009220
9221 // If we have template arguments, rebuild them, then rebuild the
9222 // templateid expression.
9223 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009224 if (Old->hasExplicitTemplateArgs() &&
9225 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009226 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009227 TransArgs)) {
9228 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009229 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009230 }
John McCalle66edc12009-11-24 19:00:30 +00009231
Abramo Bagnara7945c982012-01-27 09:46:47 +00009232 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009233 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009234}
Mike Stump11289f42009-09-09 15:08:12 +00009235
Douglas Gregora16548e2009-08-11 05:31:07 +00009236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009237ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009238TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9239 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009240 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009241 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9242 TypeSourceInfo *From = E->getArg(I);
9243 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009244 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009245 TypeLocBuilder TLB;
9246 TLB.reserve(FromTL.getFullDataSize());
9247 QualType To = getDerived().TransformType(TLB, FromTL);
9248 if (To.isNull())
9249 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009250
Douglas Gregor29c42f22012-02-24 07:38:34 +00009251 if (To == From->getType())
9252 Args.push_back(From);
9253 else {
9254 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9255 ArgChanged = true;
9256 }
9257 continue;
9258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009259
Douglas Gregor29c42f22012-02-24 07:38:34 +00009260 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
Douglas Gregor29c42f22012-02-24 07:38:34 +00009262 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009263 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009264 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9265 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9266 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009267
Douglas Gregor29c42f22012-02-24 07:38:34 +00009268 // Determine whether the set of unexpanded parameter packs can and should
9269 // be expanded.
9270 bool Expand = true;
9271 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009272 Optional<unsigned> OrigNumExpansions =
9273 ExpansionTL.getTypePtr()->getNumExpansions();
9274 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009275 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9276 PatternTL.getSourceRange(),
9277 Unexpanded,
9278 Expand, RetainExpansion,
9279 NumExpansions))
9280 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009281
Douglas Gregor29c42f22012-02-24 07:38:34 +00009282 if (!Expand) {
9283 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009284 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009285 // expansion.
9286 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009287
Douglas Gregor29c42f22012-02-24 07:38:34 +00009288 TypeLocBuilder TLB;
9289 TLB.reserve(From->getTypeLoc().getFullDataSize());
9290
9291 QualType To = getDerived().TransformType(TLB, PatternTL);
9292 if (To.isNull())
9293 return ExprError();
9294
Chad Rosier1dcde962012-08-08 18:46:20 +00009295 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009296 PatternTL.getSourceRange(),
9297 ExpansionTL.getEllipsisLoc(),
9298 NumExpansions);
9299 if (To.isNull())
9300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009301
Douglas Gregor29c42f22012-02-24 07:38:34 +00009302 PackExpansionTypeLoc ToExpansionTL
9303 = TLB.push<PackExpansionTypeLoc>(To);
9304 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9305 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9306 continue;
9307 }
9308
9309 // Expand the pack expansion by substituting for each argument in the
9310 // pack(s).
9311 for (unsigned I = 0; I != *NumExpansions; ++I) {
9312 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9313 TypeLocBuilder TLB;
9314 TLB.reserve(PatternTL.getFullDataSize());
9315 QualType To = getDerived().TransformType(TLB, PatternTL);
9316 if (To.isNull())
9317 return ExprError();
9318
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009319 if (To->containsUnexpandedParameterPack()) {
9320 To = getDerived().RebuildPackExpansionType(To,
9321 PatternTL.getSourceRange(),
9322 ExpansionTL.getEllipsisLoc(),
9323 NumExpansions);
9324 if (To.isNull())
9325 return ExprError();
9326
9327 PackExpansionTypeLoc ToExpansionTL
9328 = TLB.push<PackExpansionTypeLoc>(To);
9329 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9330 }
9331
Douglas Gregor29c42f22012-02-24 07:38:34 +00009332 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009334
Douglas Gregor29c42f22012-02-24 07:38:34 +00009335 if (!RetainExpansion)
9336 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009337
Douglas Gregor29c42f22012-02-24 07:38:34 +00009338 // If we're supposed to retain a pack expansion, do so by temporarily
9339 // forgetting the partially-substituted parameter pack.
9340 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9341
9342 TypeLocBuilder TLB;
9343 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregor29c42f22012-02-24 07:38:34 +00009345 QualType To = getDerived().TransformType(TLB, PatternTL);
9346 if (To.isNull())
9347 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009348
9349 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009350 PatternTL.getSourceRange(),
9351 ExpansionTL.getEllipsisLoc(),
9352 NumExpansions);
9353 if (To.isNull())
9354 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009355
Douglas Gregor29c42f22012-02-24 07:38:34 +00009356 PackExpansionTypeLoc ToExpansionTL
9357 = TLB.push<PackExpansionTypeLoc>(To);
9358 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9359 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009361
Douglas Gregor29c42f22012-02-24 07:38:34 +00009362 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009363 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009364
9365 return getDerived().RebuildTypeTrait(E->getTrait(),
9366 E->getLocStart(),
9367 Args,
9368 E->getLocEnd());
9369}
9370
9371template<typename Derived>
9372ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009373TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9374 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9375 if (!T)
9376 return ExprError();
9377
9378 if (!getDerived().AlwaysRebuild() &&
9379 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009380 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009381
9382 ExprResult SubExpr;
9383 {
9384 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9385 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9386 if (SubExpr.isInvalid())
9387 return ExprError();
9388
9389 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009390 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009391 }
9392
9393 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9394 E->getLocStart(),
9395 T,
9396 SubExpr.get(),
9397 E->getLocEnd());
9398}
9399
9400template<typename Derived>
9401ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009402TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9403 ExprResult SubExpr;
9404 {
9405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9406 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9407 if (SubExpr.isInvalid())
9408 return ExprError();
9409
9410 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009411 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009412 }
9413
9414 return getDerived().RebuildExpressionTrait(
9415 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9416}
9417
Reid Kleckner32506ed2014-06-12 23:03:48 +00009418template <typename Derived>
9419ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9420 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9421 TypeSourceInfo **RecoveryTSI) {
9422 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9423 DRE, AddrTaken, RecoveryTSI);
9424
9425 // Propagate both errors and recovered types, which return ExprEmpty.
9426 if (!NewDRE.isUsable())
9427 return NewDRE;
9428
9429 // We got an expr, wrap it up in parens.
9430 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9431 return PE;
9432 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9433 PE->getRParen());
9434}
9435
9436template <typename Derived>
9437ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9438 DependentScopeDeclRefExpr *E) {
9439 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9440 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009441}
9442
9443template<typename Derived>
9444ExprResult
9445TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9446 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009447 bool IsAddressOfOperand,
9448 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009449 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009450 NestedNameSpecifierLoc QualifierLoc
9451 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9452 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009453 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009454 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009455
John McCall31f82722010-11-12 08:19:04 +00009456 // TODO: If this is a conversion-function-id, verify that the
9457 // destination type name (if present) resolves the same way after
9458 // instantiation as it did in the local scope.
9459
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009460 DeclarationNameInfo NameInfo
9461 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9462 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009464
John McCalle66edc12009-11-24 19:00:30 +00009465 if (!E->hasExplicitTemplateArgs()) {
9466 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009467 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009468 // Note: it is sufficient to compare the Name component of NameInfo:
9469 // if name has not changed, DNLoc has not changed either.
9470 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009471 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009472
Reid Kleckner32506ed2014-06-12 23:03:48 +00009473 return getDerived().RebuildDependentScopeDeclRefExpr(
9474 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9475 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009476 }
John McCall6b51f282009-11-23 01:53:49 +00009477
9478 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009479 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9480 E->getNumTemplateArgs(),
9481 TransArgs))
9482 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009483
Reid Kleckner32506ed2014-06-12 23:03:48 +00009484 return getDerived().RebuildDependentScopeDeclRefExpr(
9485 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9486 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009487}
9488
9489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009491TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009492 // CXXConstructExprs other than for list-initialization and
9493 // CXXTemporaryObjectExpr are always implicit, so when we have
9494 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009495 if ((E->getNumArgs() == 1 ||
9496 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009497 (!getDerived().DropCallArgument(E->getArg(0))) &&
9498 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009499 return getDerived().TransformExpr(E->getArg(0));
9500
Douglas Gregora16548e2009-08-11 05:31:07 +00009501 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9502
9503 QualType T = getDerived().TransformType(E->getType());
9504 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009505 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009506
9507 CXXConstructorDecl *Constructor
9508 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009509 getDerived().TransformDecl(E->getLocStart(),
9510 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009511 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009513
Douglas Gregora16548e2009-08-11 05:31:07 +00009514 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009515 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009516 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009517 &ArgumentChanged))
9518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009519
Douglas Gregora16548e2009-08-11 05:31:07 +00009520 if (!getDerived().AlwaysRebuild() &&
9521 T == E->getType() &&
9522 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009523 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009524 // Mark the constructor as referenced.
9525 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009526 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009527 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009528 }
Mike Stump11289f42009-09-09 15:08:12 +00009529
Douglas Gregordb121ba2009-12-14 16:27:04 +00009530 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9531 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009532 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009533 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009534 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009535 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009536 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009537 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009538 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009539}
Mike Stump11289f42009-09-09 15:08:12 +00009540
Douglas Gregora16548e2009-08-11 05:31:07 +00009541/// \brief Transform a C++ temporary-binding expression.
9542///
Douglas Gregor363b1512009-12-24 18:51:59 +00009543/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9544/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009547TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009548 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009549}
Mike Stump11289f42009-09-09 15:08:12 +00009550
John McCall5d413782010-12-06 08:20:24 +00009551/// \brief Transform a C++ expression that contains cleanups that should
9552/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009553///
John McCall5d413782010-12-06 08:20:24 +00009554/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009555/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009557ExprResult
John McCall5d413782010-12-06 08:20:24 +00009558TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009559 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009560}
Mike Stump11289f42009-09-09 15:08:12 +00009561
Douglas Gregora16548e2009-08-11 05:31:07 +00009562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009563ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009564TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009565 CXXTemporaryObjectExpr *E) {
9566 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9567 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009569
Douglas Gregora16548e2009-08-11 05:31:07 +00009570 CXXConstructorDecl *Constructor
9571 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009572 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009573 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009574 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009575 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009576
Douglas Gregora16548e2009-08-11 05:31:07 +00009577 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009578 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009579 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009580 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009581 &ArgumentChanged))
9582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009583
Douglas Gregora16548e2009-08-11 05:31:07 +00009584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009585 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009586 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009587 !ArgumentChanged) {
9588 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009589 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009590 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009592
Richard Smithd59b8322012-12-19 01:39:02 +00009593 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009594 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9595 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009596 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009597 E->getLocEnd());
9598}
Mike Stump11289f42009-09-09 15:08:12 +00009599
Douglas Gregora16548e2009-08-11 05:31:07 +00009600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009601ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009602TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009603 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009604 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009605 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009606 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9607 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009608 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009609 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009610 CEnd = E->capture_end();
9611 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009612 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009613 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009614 EnterExpressionEvaluationContext EEEC(getSema(),
9615 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009616 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9617 C->getCapturedVar()->getInit(),
9618 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009619
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009620 if (NewExprInitResult.isInvalid())
9621 return ExprError();
9622 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009623
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009624 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009625 QualType NewInitCaptureType =
9626 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9627 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009628 NewExprInit);
9629 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009630 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9631 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009632 }
9633
Faisal Vali2cba1332013-10-23 06:44:28 +00009634 // Transform the template parameters, and add them to the current
9635 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009636 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009637 E->getTemplateParameterList());
9638
Richard Smith01014ce2014-11-20 23:53:14 +00009639 // Transform the type of the original lambda's call operator.
9640 // The transformation MUST be done in the CurrentInstantiationScope since
9641 // it introduces a mapping of the original to the newly created
9642 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009643 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009644 {
9645 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9646 FunctionProtoTypeLoc OldCallOpFPTL =
9647 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009648
9649 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009650 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009651 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009652 QualType NewCallOpType = TransformFunctionProtoType(
9653 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009654 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9655 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9656 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009657 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009658 if (NewCallOpType.isNull())
9659 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009660 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9661 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009662 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009663
Richard Smithc38498f2015-04-27 21:27:54 +00009664 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9665 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9666 LSI->GLTemplateParameterList = TPL;
9667
Eli Friedmand564afb2012-09-19 01:18:11 +00009668 // Create the local class that will describe the lambda.
9669 CXXRecordDecl *Class
9670 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009671 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009672 /*KnownDependent=*/false,
9673 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009674 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9675
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009676 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009677 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9678 Class, E->getIntroducerRange(), NewCallOpTSI,
9679 E->getCallOperator()->getLocEnd(),
9680 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009681 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009682
Faisal Vali2cba1332013-10-23 06:44:28 +00009683 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009684 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009685
Douglas Gregorb4328232012-02-14 00:00:48 +00009686 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009687 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009688 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009689
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009690 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009691 getSema().buildLambdaScope(LSI, NewCallOperator,
9692 E->getIntroducerRange(),
9693 E->getCaptureDefault(),
9694 E->getCaptureDefaultLoc(),
9695 E->hasExplicitParameters(),
9696 E->hasExplicitResultType(),
9697 E->isMutable());
9698
9699 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009701 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009702 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009703 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009704 CEnd = E->capture_end();
9705 C != CEnd; ++C) {
9706 // When we hit the first implicit capture, tell Sema that we've finished
9707 // the list of explicit captures.
9708 if (!FinishedExplicitCaptures && C->isImplicit()) {
9709 getSema().finishLambdaExplicitCaptures(LSI);
9710 FinishedExplicitCaptures = true;
9711 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009712
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009713 // Capturing 'this' is trivial.
9714 if (C->capturesThis()) {
9715 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9716 continue;
9717 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009718 // Captured expression will be recaptured during captured variables
9719 // rebuilding.
9720 if (C->capturesVLAType())
9721 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009722
Richard Smithba71c082013-05-16 06:20:58 +00009723 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009724 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009725 InitCaptureInfoTy InitExprTypePair =
9726 InitCaptureExprsAndTypes[C - E->capture_begin()];
9727 ExprResult Init = InitExprTypePair.first;
9728 QualType InitQualType = InitExprTypePair.second;
9729 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009730 Invalid = true;
9731 continue;
9732 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009733 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009734 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9735 OldVD->getLocation(), InitExprTypePair.second,
9736 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009737 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009738 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009739 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009740 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009741 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009742 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009743 continue;
9744 }
9745
9746 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9747
Douglas Gregor3e308b12012-02-14 19:27:52 +00009748 // Determine the capture kind for Sema.
9749 Sema::TryCaptureKind Kind
9750 = C->isImplicit()? Sema::TryCapture_Implicit
9751 : C->getCaptureKind() == LCK_ByCopy
9752 ? Sema::TryCapture_ExplicitByVal
9753 : Sema::TryCapture_ExplicitByRef;
9754 SourceLocation EllipsisLoc;
9755 if (C->isPackExpansion()) {
9756 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9757 bool ShouldExpand = false;
9758 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009759 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009760 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9761 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009762 Unexpanded,
9763 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009764 NumExpansions)) {
9765 Invalid = true;
9766 continue;
9767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009768
Douglas Gregor3e308b12012-02-14 19:27:52 +00009769 if (ShouldExpand) {
9770 // The transform has determined that we should perform an expansion;
9771 // transform and capture each of the arguments.
9772 // expansion of the pattern. Do so.
9773 VarDecl *Pack = C->getCapturedVar();
9774 for (unsigned I = 0; I != *NumExpansions; ++I) {
9775 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9776 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009777 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009778 Pack));
9779 if (!CapturedVar) {
9780 Invalid = true;
9781 continue;
9782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
Douglas Gregor3e308b12012-02-14 19:27:52 +00009784 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009785 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9786 }
Richard Smith9467be42014-06-06 17:33:35 +00009787
9788 // FIXME: Retain a pack expansion if RetainExpansion is true.
9789
Douglas Gregor3e308b12012-02-14 19:27:52 +00009790 continue;
9791 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009792
Douglas Gregor3e308b12012-02-14 19:27:52 +00009793 EllipsisLoc = C->getEllipsisLoc();
9794 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009795
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009796 // Transform the captured variable.
9797 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009798 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009799 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009800 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009801 Invalid = true;
9802 continue;
9803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009804
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009805 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009806 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9807 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009808 }
9809 if (!FinishedExplicitCaptures)
9810 getSema().finishLambdaExplicitCaptures(LSI);
9811
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009812 // Enter a new evaluation context to insulate the lambda from any
9813 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009814 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009815
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009816 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009817 StmtResult Body =
9818 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9819
9820 // ActOnLambda* will pop the function scope for us.
9821 FuncScopeCleanup.disable();
9822
Douglas Gregorb4328232012-02-14 00:00:48 +00009823 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009824 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009825 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009826 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009827 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009828 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009829
Richard Smithc38498f2015-04-27 21:27:54 +00009830 // Copy the LSI before ActOnFinishFunctionBody removes it.
9831 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9832 // the call operator.
9833 auto LSICopy = *LSI;
9834 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9835 /*IsInstantiation*/ true);
9836 SavedContext.pop();
9837
9838 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9839 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009840}
9841
9842template<typename Derived>
9843ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009844TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009845 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009846 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9847 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009849
Douglas Gregora16548e2009-08-11 05:31:07 +00009850 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009851 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009852 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009853 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009854 &ArgumentChanged))
9855 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009856
Douglas Gregora16548e2009-08-11 05:31:07 +00009857 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009858 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009860 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009861
Douglas Gregora16548e2009-08-11 05:31:07 +00009862 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009863 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009864 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009865 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009866 E->getRParenLoc());
9867}
Mike Stump11289f42009-09-09 15:08:12 +00009868
Douglas Gregora16548e2009-08-11 05:31:07 +00009869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009870ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009871TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009872 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009873 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009874 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009875 Expr *OldBase;
9876 QualType BaseType;
9877 QualType ObjectType;
9878 if (!E->isImplicitAccess()) {
9879 OldBase = E->getBase();
9880 Base = getDerived().TransformExpr(OldBase);
9881 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009883
John McCall2d74de92009-12-01 22:10:20 +00009884 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009885 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009886 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009887 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009888 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009889 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009890 ObjectTy,
9891 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009892 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009893 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009894
John McCallba7bf592010-08-24 05:47:05 +00009895 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009896 BaseType = ((Expr*) Base.get())->getType();
9897 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009898 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009899 BaseType = getDerived().TransformType(E->getBaseType());
9900 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9901 }
Mike Stump11289f42009-09-09 15:08:12 +00009902
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009903 // Transform the first part of the nested-name-specifier that qualifies
9904 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009905 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009906 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009907 E->getFirstQualifierFoundInScope(),
9908 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009909
Douglas Gregore16af532011-02-28 18:50:33 +00009910 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009911 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009912 QualifierLoc
9913 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9914 ObjectType,
9915 FirstQualifierInScope);
9916 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009917 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009918 }
Mike Stump11289f42009-09-09 15:08:12 +00009919
Abramo Bagnara7945c982012-01-27 09:46:47 +00009920 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9921
John McCall31f82722010-11-12 08:19:04 +00009922 // TODO: If this is a conversion-function-id, verify that the
9923 // destination type name (if present) resolves the same way after
9924 // instantiation as it did in the local scope.
9925
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009926 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009927 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009928 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009930
John McCall2d74de92009-12-01 22:10:20 +00009931 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009932 // This is a reference to a member without an explicitly-specified
9933 // template argument list. Optimize for this common case.
9934 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009935 Base.get() == OldBase &&
9936 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009937 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009938 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009939 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009940 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009941
John McCallb268a282010-08-23 23:25:46 +00009942 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009943 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009944 E->isArrow(),
9945 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009946 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009947 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009948 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009949 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009950 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009951 }
9952
John McCall6b51f282009-11-23 01:53:49 +00009953 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009954 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9955 E->getNumTemplateArgs(),
9956 TransArgs))
9957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009958
John McCallb268a282010-08-23 23:25:46 +00009959 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009960 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009961 E->isArrow(),
9962 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009963 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009964 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009965 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009966 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009967 &TransArgs);
9968}
9969
9970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009972TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009973 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009974 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009975 QualType BaseType;
9976 if (!Old->isImplicitAccess()) {
9977 Base = getDerived().TransformExpr(Old->getBase());
9978 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009979 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009980 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009981 Old->isArrow());
9982 if (Base.isInvalid())
9983 return ExprError();
9984 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009985 } else {
9986 BaseType = getDerived().TransformType(Old->getBaseType());
9987 }
John McCall10eae182009-11-30 22:42:35 +00009988
Douglas Gregor0da1d432011-02-28 20:01:57 +00009989 NestedNameSpecifierLoc QualifierLoc;
9990 if (Old->getQualifierLoc()) {
9991 QualifierLoc
9992 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9993 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009994 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009995 }
9996
Abramo Bagnara7945c982012-01-27 09:46:47 +00009997 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9998
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009999 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010000 Sema::LookupOrdinaryName);
10001
10002 // Transform all the decls.
10003 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10004 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010005 NamedDecl *InstD = static_cast<NamedDecl*>(
10006 getDerived().TransformDecl(Old->getMemberLoc(),
10007 *I));
John McCall84d87672009-12-10 09:41:52 +000010008 if (!InstD) {
10009 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10010 // This can happen because of dependent hiding.
10011 if (isa<UsingShadowDecl>(*I))
10012 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010013 else {
10014 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010015 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010016 }
John McCall84d87672009-12-10 09:41:52 +000010017 }
John McCall10eae182009-11-30 22:42:35 +000010018
10019 // Expand using declarations.
10020 if (isa<UsingDecl>(InstD)) {
10021 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010022 for (auto *I : UD->shadows())
10023 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010024 continue;
10025 }
10026
10027 R.addDecl(InstD);
10028 }
10029
10030 R.resolveKind();
10031
Douglas Gregor9262f472010-04-27 18:19:34 +000010032 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010033 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010034 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010035 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010036 Old->getMemberLoc(),
10037 Old->getNamingClass()));
10038 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010039 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010040
Douglas Gregorda7be082010-04-27 16:10:10 +000010041 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010042 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010043
John McCall10eae182009-11-30 22:42:35 +000010044 TemplateArgumentListInfo TransArgs;
10045 if (Old->hasExplicitTemplateArgs()) {
10046 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10047 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010048 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10049 Old->getNumTemplateArgs(),
10050 TransArgs))
10051 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010052 }
John McCall38836f02010-01-15 08:34:02 +000010053
10054 // FIXME: to do this check properly, we will need to preserve the
10055 // first-qualifier-in-scope here, just in case we had a dependent
10056 // base (and therefore couldn't do the check) and a
10057 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010058 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010059
John McCallb268a282010-08-23 23:25:46 +000010060 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010061 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010062 Old->getOperatorLoc(),
10063 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010064 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010065 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010066 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010067 R,
10068 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010069 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010070}
10071
10072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010073ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010074TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010076 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10077 if (SubExpr.isInvalid())
10078 return ExprError();
10079
10080 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010081 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010082
10083 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10084}
10085
10086template<typename Derived>
10087ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010088TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010089 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10090 if (Pattern.isInvalid())
10091 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010092
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010093 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010094 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010095
Douglas Gregorb8840002011-01-14 21:20:45 +000010096 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10097 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010098}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010099
10100template<typename Derived>
10101ExprResult
10102TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10103 // If E is not value-dependent, then nothing will change when we transform it.
10104 // Note: This is an instantiation-centric view.
10105 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010106 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010107
Richard Smithd784e682015-09-23 21:41:42 +000010108 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010109
Richard Smithd784e682015-09-23 21:41:42 +000010110 ArrayRef<TemplateArgument> PackArgs;
10111 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010112
Richard Smithd784e682015-09-23 21:41:42 +000010113 // Find the argument list to transform.
10114 if (E->isPartiallySubstituted()) {
10115 PackArgs = E->getPartialArguments();
10116 } else if (E->isValueDependent()) {
10117 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10118 bool ShouldExpand = false;
10119 bool RetainExpansion = false;
10120 Optional<unsigned> NumExpansions;
10121 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10122 Unexpanded,
10123 ShouldExpand, RetainExpansion,
10124 NumExpansions))
10125 return ExprError();
10126
10127 // If we need to expand the pack, build a template argument from it and
10128 // expand that.
10129 if (ShouldExpand) {
10130 auto *Pack = E->getPack();
10131 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10132 ArgStorage = getSema().Context.getPackExpansionType(
10133 getSema().Context.getTypeDeclType(TTPD), None);
10134 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10135 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10136 } else {
10137 auto *VD = cast<ValueDecl>(Pack);
10138 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10139 VK_RValue, E->getPackLoc());
10140 if (DRE.isInvalid())
10141 return ExprError();
10142 ArgStorage = new (getSema().Context) PackExpansionExpr(
10143 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10144 }
10145 PackArgs = ArgStorage;
10146 }
10147 }
10148
10149 // If we're not expanding the pack, just transform the decl.
10150 if (!PackArgs.size()) {
10151 auto *Pack = cast_or_null<NamedDecl>(
10152 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010153 if (!Pack)
10154 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010155 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10156 E->getPackLoc(),
10157 E->getRParenLoc(), None, None);
10158 }
10159
10160 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10161 E->getPackLoc());
10162 {
10163 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10164 typedef TemplateArgumentLocInventIterator<
10165 Derived, const TemplateArgument*> PackLocIterator;
10166 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10167 PackLocIterator(*this, PackArgs.end()),
10168 TransformedPackArgs, /*Uneval*/true))
10169 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010170 }
10171
Richard Smithd784e682015-09-23 21:41:42 +000010172 SmallVector<TemplateArgument, 8> Args;
10173 bool PartialSubstitution = false;
10174 for (auto &Loc : TransformedPackArgs.arguments()) {
10175 Args.push_back(Loc.getArgument());
10176 if (Loc.getArgument().isPackExpansion())
10177 PartialSubstitution = true;
10178 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010179
Richard Smithd784e682015-09-23 21:41:42 +000010180 if (PartialSubstitution)
10181 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10182 E->getPackLoc(),
10183 E->getRParenLoc(), None, Args);
10184
10185 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010186 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010187 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010188}
10189
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010190template<typename Derived>
10191ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010192TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10193 SubstNonTypeTemplateParmPackExpr *E) {
10194 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010195 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010196}
10197
10198template<typename Derived>
10199ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010200TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10201 SubstNonTypeTemplateParmExpr *E) {
10202 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010203 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010204}
10205
10206template<typename Derived>
10207ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010208TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10209 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010210 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010211}
10212
10213template<typename Derived>
10214ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010215TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10216 MaterializeTemporaryExpr *E) {
10217 return getDerived().TransformExpr(E->GetTemporaryExpr());
10218}
Chad Rosier1dcde962012-08-08 18:46:20 +000010219
Douglas Gregorfe314812011-06-21 17:03:29 +000010220template<typename Derived>
10221ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010222TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10223 Expr *Pattern = E->getPattern();
10224
10225 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10226 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10227 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10228
10229 // Determine whether the set of unexpanded parameter packs can and should
10230 // be expanded.
10231 bool Expand = true;
10232 bool RetainExpansion = false;
10233 Optional<unsigned> NumExpansions;
10234 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10235 Pattern->getSourceRange(),
10236 Unexpanded,
10237 Expand, RetainExpansion,
10238 NumExpansions))
10239 return true;
10240
10241 if (!Expand) {
10242 // Do not expand any packs here, just transform and rebuild a fold
10243 // expression.
10244 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10245
10246 ExprResult LHS =
10247 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10248 if (LHS.isInvalid())
10249 return true;
10250
10251 ExprResult RHS =
10252 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10253 if (RHS.isInvalid())
10254 return true;
10255
10256 if (!getDerived().AlwaysRebuild() &&
10257 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10258 return E;
10259
10260 return getDerived().RebuildCXXFoldExpr(
10261 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10262 RHS.get(), E->getLocEnd());
10263 }
10264
10265 // The transform has determined that we should perform an elementwise
10266 // expansion of the pattern. Do so.
10267 ExprResult Result = getDerived().TransformExpr(E->getInit());
10268 if (Result.isInvalid())
10269 return true;
10270 bool LeftFold = E->isLeftFold();
10271
10272 // If we're retaining an expansion for a right fold, it is the innermost
10273 // component and takes the init (if any).
10274 if (!LeftFold && RetainExpansion) {
10275 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10276
10277 ExprResult Out = getDerived().TransformExpr(Pattern);
10278 if (Out.isInvalid())
10279 return true;
10280
10281 Result = getDerived().RebuildCXXFoldExpr(
10282 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10283 Result.get(), E->getLocEnd());
10284 if (Result.isInvalid())
10285 return true;
10286 }
10287
10288 for (unsigned I = 0; I != *NumExpansions; ++I) {
10289 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10290 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10291 ExprResult Out = getDerived().TransformExpr(Pattern);
10292 if (Out.isInvalid())
10293 return true;
10294
10295 if (Out.get()->containsUnexpandedParameterPack()) {
10296 // We still have a pack; retain a pack expansion for this slice.
10297 Result = getDerived().RebuildCXXFoldExpr(
10298 E->getLocStart(),
10299 LeftFold ? Result.get() : Out.get(),
10300 E->getOperator(), E->getEllipsisLoc(),
10301 LeftFold ? Out.get() : Result.get(),
10302 E->getLocEnd());
10303 } else if (Result.isUsable()) {
10304 // We've got down to a single element; build a binary operator.
10305 Result = getDerived().RebuildBinaryOperator(
10306 E->getEllipsisLoc(), E->getOperator(),
10307 LeftFold ? Result.get() : Out.get(),
10308 LeftFold ? Out.get() : Result.get());
10309 } else
10310 Result = Out;
10311
10312 if (Result.isInvalid())
10313 return true;
10314 }
10315
10316 // If we're retaining an expansion for a left fold, it is the outermost
10317 // component and takes the complete expansion so far as its init (if any).
10318 if (LeftFold && RetainExpansion) {
10319 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10320
10321 ExprResult Out = getDerived().TransformExpr(Pattern);
10322 if (Out.isInvalid())
10323 return true;
10324
10325 Result = getDerived().RebuildCXXFoldExpr(
10326 E->getLocStart(), Result.get(),
10327 E->getOperator(), E->getEllipsisLoc(),
10328 Out.get(), E->getLocEnd());
10329 if (Result.isInvalid())
10330 return true;
10331 }
10332
10333 // If we had no init and an empty pack, and we're not retaining an expansion,
10334 // then produce a fallback value or error.
10335 if (Result.isUnset())
10336 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10337 E->getOperator());
10338
10339 return Result;
10340}
10341
10342template<typename Derived>
10343ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010344TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10345 CXXStdInitializerListExpr *E) {
10346 return getDerived().TransformExpr(E->getSubExpr());
10347}
10348
10349template<typename Derived>
10350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010351TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010352 return SemaRef.MaybeBindToTemporary(E);
10353}
10354
10355template<typename Derived>
10356ExprResult
10357TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010358 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010359}
10360
10361template<typename Derived>
10362ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010363TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10364 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10365 if (SubExpr.isInvalid())
10366 return ExprError();
10367
10368 if (!getDerived().AlwaysRebuild() &&
10369 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010370 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010371
10372 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010373}
10374
10375template<typename Derived>
10376ExprResult
10377TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10378 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010379 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010380 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010381 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010382 /*IsCall=*/false, Elements, &ArgChanged))
10383 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010384
Ted Kremeneke65b0862012-03-06 20:05:56 +000010385 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10386 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010387
Ted Kremeneke65b0862012-03-06 20:05:56 +000010388 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10389 Elements.data(),
10390 Elements.size());
10391}
10392
10393template<typename Derived>
10394ExprResult
10395TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010396 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010397 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010398 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010399 bool ArgChanged = false;
10400 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10401 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010402
Ted Kremeneke65b0862012-03-06 20:05:56 +000010403 if (OrigElement.isPackExpansion()) {
10404 // This key/value element is a pack expansion.
10405 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10406 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10407 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10408 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10409
10410 // Determine whether the set of unexpanded parameter packs can
10411 // and should be expanded.
10412 bool Expand = true;
10413 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010414 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10415 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010416 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10417 OrigElement.Value->getLocEnd());
10418 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10419 PatternRange,
10420 Unexpanded,
10421 Expand, RetainExpansion,
10422 NumExpansions))
10423 return ExprError();
10424
10425 if (!Expand) {
10426 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010427 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010428 // expansion.
10429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10430 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10431 if (Key.isInvalid())
10432 return ExprError();
10433
10434 if (Key.get() != OrigElement.Key)
10435 ArgChanged = true;
10436
10437 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10438 if (Value.isInvalid())
10439 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010440
Ted Kremeneke65b0862012-03-06 20:05:56 +000010441 if (Value.get() != OrigElement.Value)
10442 ArgChanged = true;
10443
Chad Rosier1dcde962012-08-08 18:46:20 +000010444 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010445 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10446 };
10447 Elements.push_back(Expansion);
10448 continue;
10449 }
10450
10451 // Record right away that the argument was changed. This needs
10452 // to happen even if the array expands to nothing.
10453 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010454
Ted Kremeneke65b0862012-03-06 20:05:56 +000010455 // The transform has determined that we should perform an elementwise
10456 // expansion of the pattern. Do so.
10457 for (unsigned I = 0; I != *NumExpansions; ++I) {
10458 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10459 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10460 if (Key.isInvalid())
10461 return ExprError();
10462
10463 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10464 if (Value.isInvalid())
10465 return ExprError();
10466
Chad Rosier1dcde962012-08-08 18:46:20 +000010467 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010468 Key.get(), Value.get(), SourceLocation(), NumExpansions
10469 };
10470
10471 // If any unexpanded parameter packs remain, we still have a
10472 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010473 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010474 if (Key.get()->containsUnexpandedParameterPack() ||
10475 Value.get()->containsUnexpandedParameterPack())
10476 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010477
Ted Kremeneke65b0862012-03-06 20:05:56 +000010478 Elements.push_back(Element);
10479 }
10480
Richard Smith9467be42014-06-06 17:33:35 +000010481 // FIXME: Retain a pack expansion if RetainExpansion is true.
10482
Ted Kremeneke65b0862012-03-06 20:05:56 +000010483 // We've finished with this pack expansion.
10484 continue;
10485 }
10486
10487 // Transform and check key.
10488 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10489 if (Key.isInvalid())
10490 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010491
Ted Kremeneke65b0862012-03-06 20:05:56 +000010492 if (Key.get() != OrigElement.Key)
10493 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010494
Ted Kremeneke65b0862012-03-06 20:05:56 +000010495 // Transform and check value.
10496 ExprResult Value
10497 = getDerived().TransformExpr(OrigElement.Value);
10498 if (Value.isInvalid())
10499 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010500
Ted Kremeneke65b0862012-03-06 20:05:56 +000010501 if (Value.get() != OrigElement.Value)
10502 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010503
10504 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010505 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010506 };
10507 Elements.push_back(Element);
10508 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010509
Ted Kremeneke65b0862012-03-06 20:05:56 +000010510 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10511 return SemaRef.MaybeBindToTemporary(E);
10512
10513 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10514 Elements.data(),
10515 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010516}
10517
Mike Stump11289f42009-09-09 15:08:12 +000010518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010520TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010521 TypeSourceInfo *EncodedTypeInfo
10522 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10523 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010525
Douglas Gregora16548e2009-08-11 05:31:07 +000010526 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010527 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010528 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010529
10530 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010531 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010532 E->getRParenLoc());
10533}
Mike Stump11289f42009-09-09 15:08:12 +000010534
Douglas Gregora16548e2009-08-11 05:31:07 +000010535template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010536ExprResult TreeTransform<Derived>::
10537TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010538 // This is a kind of implicit conversion, and it needs to get dropped
10539 // and recomputed for the same general reasons that ImplicitCastExprs
10540 // do, as well a more specific one: this expression is only valid when
10541 // it appears *immediately* as an argument expression.
10542 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010543}
10544
10545template<typename Derived>
10546ExprResult TreeTransform<Derived>::
10547TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010548 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010549 = getDerived().TransformType(E->getTypeInfoAsWritten());
10550 if (!TSInfo)
10551 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010552
John McCall31168b02011-06-15 23:02:42 +000010553 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010554 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010555 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010556
John McCall31168b02011-06-15 23:02:42 +000010557 if (!getDerived().AlwaysRebuild() &&
10558 TSInfo == E->getTypeInfoAsWritten() &&
10559 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010560 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010561
John McCall31168b02011-06-15 23:02:42 +000010562 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010563 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010564 Result.get());
10565}
10566
10567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010569TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010570 // Transform arguments.
10571 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010572 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010573 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010574 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010575 &ArgChanged))
10576 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010577
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010578 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10579 // Class message: transform the receiver type.
10580 TypeSourceInfo *ReceiverTypeInfo
10581 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10582 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010583 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010584
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010585 // If nothing changed, just retain the existing message send.
10586 if (!getDerived().AlwaysRebuild() &&
10587 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010588 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010589
10590 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010591 SmallVector<SourceLocation, 16> SelLocs;
10592 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010593 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10594 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010595 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010596 E->getMethodDecl(),
10597 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010598 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010599 E->getRightLoc());
10600 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010601 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10602 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10603 // Build a new class message send to 'super'.
10604 SmallVector<SourceLocation, 16> SelLocs;
10605 E->getSelectorLocs(SelLocs);
10606 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10607 E->getSelector(),
10608 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010609 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010610 E->getMethodDecl(),
10611 E->getLeftLoc(),
10612 Args,
10613 E->getRightLoc());
10614 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010615
10616 // Instance message: transform the receiver
10617 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10618 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010619 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010620 = getDerived().TransformExpr(E->getInstanceReceiver());
10621 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010622 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010623
10624 // If nothing changed, just retain the existing message send.
10625 if (!getDerived().AlwaysRebuild() &&
10626 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010627 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010628
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010629 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010630 SmallVector<SourceLocation, 16> SelLocs;
10631 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010632 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010633 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010634 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010635 E->getMethodDecl(),
10636 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010637 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010638 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010639}
10640
Mike Stump11289f42009-09-09 15:08:12 +000010641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010643TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010644 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010645}
10646
Mike Stump11289f42009-09-09 15:08:12 +000010647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010649TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010650 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010651}
10652
Mike Stump11289f42009-09-09 15:08:12 +000010653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010655TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010656 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010658 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010659 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010660
10661 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010662
Douglas Gregord51d90d2010-04-26 20:11:03 +000010663 // If nothing changed, just retain the existing expression.
10664 if (!getDerived().AlwaysRebuild() &&
10665 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010666 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010667
John McCallb268a282010-08-23 23:25:46 +000010668 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010669 E->getLocation(),
10670 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010671}
10672
Mike Stump11289f42009-09-09 15:08:12 +000010673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010675TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010676 // 'super' and types never change. Property never changes. Just
10677 // retain the existing expression.
10678 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010679 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010680
Douglas Gregor9faee212010-04-26 20:47:02 +000010681 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010683 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010684 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010685
Douglas Gregor9faee212010-04-26 20:47:02 +000010686 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010687
Douglas Gregor9faee212010-04-26 20:47:02 +000010688 // If nothing changed, just retain the existing expression.
10689 if (!getDerived().AlwaysRebuild() &&
10690 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010691 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010692
John McCallb7bd14f2010-12-02 01:19:52 +000010693 if (E->isExplicitProperty())
10694 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10695 E->getExplicitProperty(),
10696 E->getLocation());
10697
10698 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010699 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010700 E->getImplicitPropertyGetter(),
10701 E->getImplicitPropertySetter(),
10702 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010703}
10704
Mike Stump11289f42009-09-09 15:08:12 +000010705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010706ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010707TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10708 // Transform the base expression.
10709 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10710 if (Base.isInvalid())
10711 return ExprError();
10712
10713 // Transform the key expression.
10714 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10715 if (Key.isInvalid())
10716 return ExprError();
10717
10718 // If nothing changed, just retain the existing expression.
10719 if (!getDerived().AlwaysRebuild() &&
10720 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010721 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010722
Chad Rosier1dcde962012-08-08 18:46:20 +000010723 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010724 Base.get(), Key.get(),
10725 E->getAtIndexMethodDecl(),
10726 E->setAtIndexMethodDecl());
10727}
10728
10729template<typename Derived>
10730ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010731TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010732 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010733 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010734 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010735 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010736
Douglas Gregord51d90d2010-04-26 20:11:03 +000010737 // If nothing changed, just retain the existing expression.
10738 if (!getDerived().AlwaysRebuild() &&
10739 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010740 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010741
John McCallb268a282010-08-23 23:25:46 +000010742 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010743 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010744 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010745}
10746
Mike Stump11289f42009-09-09 15:08:12 +000010747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010749TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010750 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010751 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010752 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010753 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010754 SubExprs, &ArgumentChanged))
10755 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010756
Douglas Gregora16548e2009-08-11 05:31:07 +000010757 if (!getDerived().AlwaysRebuild() &&
10758 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010759 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010760
Douglas Gregora16548e2009-08-11 05:31:07 +000010761 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010762 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010763 E->getRParenLoc());
10764}
10765
Mike Stump11289f42009-09-09 15:08:12 +000010766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010767ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010768TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10769 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10770 if (SrcExpr.isInvalid())
10771 return ExprError();
10772
10773 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10774 if (!Type)
10775 return ExprError();
10776
10777 if (!getDerived().AlwaysRebuild() &&
10778 Type == E->getTypeSourceInfo() &&
10779 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010780 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010781
10782 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10783 SrcExpr.get(), Type,
10784 E->getRParenLoc());
10785}
10786
10787template<typename Derived>
10788ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010789TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010790 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010791
Craig Topperc3ec1492014-05-26 06:22:03 +000010792 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010793 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10794
10795 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010796 blockScope->TheDecl->setBlockMissingReturnType(
10797 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010798
Chris Lattner01cf8db2011-07-20 06:58:45 +000010799 SmallVector<ParmVarDecl*, 4> params;
10800 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010801
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010802 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010803 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10804 oldBlock->param_begin(),
10805 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010806 nullptr, paramTypes, &params)) {
10807 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010808 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010809 }
John McCall490112f2011-02-04 18:33:18 +000010810
Jordan Rosea0a86be2013-03-08 22:25:36 +000010811 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010812 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010813 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010814
Jordan Rose5c382722013-03-08 21:51:21 +000010815 QualType functionType =
10816 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010817 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010818 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010819
10820 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010821 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010822 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010823
10824 if (!oldBlock->blockMissingReturnType()) {
10825 blockScope->HasImplicitReturnType = false;
10826 blockScope->ReturnType = exprResultType;
10827 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010828
John McCall3882ace2011-01-05 12:14:39 +000010829 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010830 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010831 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010832 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010833 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010834 }
John McCall3882ace2011-01-05 12:14:39 +000010835
John McCall490112f2011-02-04 18:33:18 +000010836#ifndef NDEBUG
10837 // In builds with assertions, make sure that we captured everything we
10838 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010839 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010840 for (const auto &I : oldBlock->captures()) {
10841 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010842
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010843 // Ignore parameter packs.
10844 if (isa<ParmVarDecl>(oldCapture) &&
10845 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10846 continue;
John McCall490112f2011-02-04 18:33:18 +000010847
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010848 VarDecl *newCapture =
10849 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10850 oldCapture));
10851 assert(blockScope->CaptureMap.count(newCapture));
10852 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010853 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010854 }
10855#endif
10856
10857 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010858 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010859}
10860
Mike Stump11289f42009-09-09 15:08:12 +000010861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010862ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010863TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010864 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010865}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010866
10867template<typename Derived>
10868ExprResult
10869TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010870 QualType RetTy = getDerived().TransformType(E->getType());
10871 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010872 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010873 SubExprs.reserve(E->getNumSubExprs());
10874 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10875 SubExprs, &ArgumentChanged))
10876 return ExprError();
10877
10878 if (!getDerived().AlwaysRebuild() &&
10879 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010880 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010881
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010882 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010883 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010884}
Chad Rosier1dcde962012-08-08 18:46:20 +000010885
Douglas Gregora16548e2009-08-11 05:31:07 +000010886//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010887// Type reconstruction
10888//===----------------------------------------------------------------------===//
10889
Mike Stump11289f42009-09-09 15:08:12 +000010890template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010891QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10892 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010893 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010894 getDerived().getBaseEntity());
10895}
10896
Mike Stump11289f42009-09-09 15:08:12 +000010897template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010898QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10899 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010900 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010901 getDerived().getBaseEntity());
10902}
10903
Mike Stump11289f42009-09-09 15:08:12 +000010904template<typename Derived>
10905QualType
John McCall70dd5f62009-10-30 00:06:24 +000010906TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10907 bool WrittenAsLValue,
10908 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010909 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010910 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010911}
10912
10913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010914QualType
John McCall70dd5f62009-10-30 00:06:24 +000010915TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10916 QualType ClassType,
10917 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010918 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10919 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010920}
10921
10922template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010923QualType TreeTransform<Derived>::RebuildObjCObjectType(
10924 QualType BaseType,
10925 SourceLocation Loc,
10926 SourceLocation TypeArgsLAngleLoc,
10927 ArrayRef<TypeSourceInfo *> TypeArgs,
10928 SourceLocation TypeArgsRAngleLoc,
10929 SourceLocation ProtocolLAngleLoc,
10930 ArrayRef<ObjCProtocolDecl *> Protocols,
10931 ArrayRef<SourceLocation> ProtocolLocs,
10932 SourceLocation ProtocolRAngleLoc) {
10933 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10934 TypeArgs, TypeArgsRAngleLoc,
10935 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10936 ProtocolRAngleLoc,
10937 /*FailOnError=*/true);
10938}
10939
10940template<typename Derived>
10941QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10942 QualType PointeeType,
10943 SourceLocation Star) {
10944 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10945}
10946
10947template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010948QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010949TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10950 ArrayType::ArraySizeModifier SizeMod,
10951 const llvm::APInt *Size,
10952 Expr *SizeExpr,
10953 unsigned IndexTypeQuals,
10954 SourceRange BracketsRange) {
10955 if (SizeExpr || !Size)
10956 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10957 IndexTypeQuals, BracketsRange,
10958 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010959
10960 QualType Types[] = {
10961 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10962 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10963 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010964 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010965 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010966 QualType SizeType;
10967 for (unsigned I = 0; I != NumTypes; ++I)
10968 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10969 SizeType = Types[I];
10970 break;
10971 }
Mike Stump11289f42009-09-09 15:08:12 +000010972
Eli Friedman9562f392012-01-25 23:20:27 +000010973 // Note that we can return a VariableArrayType here in the case where
10974 // the element type was a dependent VariableArrayType.
10975 IntegerLiteral *ArraySize
10976 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10977 /*FIXME*/BracketsRange.getBegin());
10978 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010979 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010980 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010981}
Mike Stump11289f42009-09-09 15:08:12 +000010982
Douglas Gregord6ff3322009-08-04 16:50:30 +000010983template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010984QualType
10985TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010986 ArrayType::ArraySizeModifier SizeMod,
10987 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010988 unsigned IndexTypeQuals,
10989 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010990 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010991 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010992}
10993
10994template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010995QualType
Mike Stump11289f42009-09-09 15:08:12 +000010996TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010997 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010998 unsigned IndexTypeQuals,
10999 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011000 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011001 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011002}
Mike Stump11289f42009-09-09 15:08:12 +000011003
Douglas Gregord6ff3322009-08-04 16:50:30 +000011004template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011005QualType
11006TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011007 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011008 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011009 unsigned IndexTypeQuals,
11010 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011011 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011012 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011013 IndexTypeQuals, BracketsRange);
11014}
11015
11016template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011017QualType
11018TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011019 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011020 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011021 unsigned IndexTypeQuals,
11022 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011023 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011024 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011025 IndexTypeQuals, BracketsRange);
11026}
11027
11028template<typename Derived>
11029QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011030 unsigned NumElements,
11031 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011032 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011033 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011034}
Mike Stump11289f42009-09-09 15:08:12 +000011035
Douglas Gregord6ff3322009-08-04 16:50:30 +000011036template<typename Derived>
11037QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11038 unsigned NumElements,
11039 SourceLocation AttributeLoc) {
11040 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11041 NumElements, true);
11042 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011043 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11044 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011045 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011046}
Mike Stump11289f42009-09-09 15:08:12 +000011047
Douglas Gregord6ff3322009-08-04 16:50:30 +000011048template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011049QualType
11050TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011051 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011052 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011053 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011054}
Mike Stump11289f42009-09-09 15:08:12 +000011055
Douglas Gregord6ff3322009-08-04 16:50:30 +000011056template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011057QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11058 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011059 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011060 const FunctionProtoType::ExtProtoInfo &EPI) {
11061 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011062 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011063 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011064 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011065}
Mike Stump11289f42009-09-09 15:08:12 +000011066
Douglas Gregord6ff3322009-08-04 16:50:30 +000011067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011068QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11069 return SemaRef.Context.getFunctionNoProtoType(T);
11070}
11071
11072template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011073QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11074 assert(D && "no decl found");
11075 if (D->isInvalidDecl()) return QualType();
11076
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011077 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011078 TypeDecl *Ty;
11079 if (isa<UsingDecl>(D)) {
11080 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011081 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011082 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11083
11084 // A valid resolved using typename decl points to exactly one type decl.
11085 assert(++Using->shadow_begin() == Using->shadow_end());
11086 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011087
John McCallb96ec562009-12-04 22:46:56 +000011088 } else {
11089 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11090 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11091 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11092 }
11093
11094 return SemaRef.Context.getTypeDeclType(Ty);
11095}
11096
11097template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011098QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11099 SourceLocation Loc) {
11100 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011101}
11102
11103template<typename Derived>
11104QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11105 return SemaRef.Context.getTypeOfType(Underlying);
11106}
11107
11108template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011109QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11110 SourceLocation Loc) {
11111 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011112}
11113
11114template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011115QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11116 UnaryTransformType::UTTKind UKind,
11117 SourceLocation Loc) {
11118 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11119}
11120
11121template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011122QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011123 TemplateName Template,
11124 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011125 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011126 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011127}
Mike Stump11289f42009-09-09 15:08:12 +000011128
Douglas Gregor1135c352009-08-06 05:28:30 +000011129template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011130QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11131 SourceLocation KWLoc) {
11132 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11133}
11134
11135template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011136TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011137TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011138 bool TemplateKW,
11139 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011140 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011141 Template);
11142}
11143
11144template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011145TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011146TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11147 const IdentifierInfo &Name,
11148 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011149 QualType ObjectType,
11150 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011151 UnqualifiedId TemplateName;
11152 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011153 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011154 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011155 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011156 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011157 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011158 /*EnteringContext=*/false,
11159 Template);
John McCall31f82722010-11-12 08:19:04 +000011160 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011161}
Mike Stump11289f42009-09-09 15:08:12 +000011162
Douglas Gregora16548e2009-08-11 05:31:07 +000011163template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011164TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011165TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011166 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011167 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011168 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011169 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011170 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011171 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011172 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011173 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011174 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011175 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011176 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011177 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011178 /*EnteringContext=*/false,
11179 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011180 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011181}
Chad Rosier1dcde962012-08-08 18:46:20 +000011182
Douglas Gregor71395fa2009-11-04 00:56:37 +000011183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011184ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011185TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11186 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011187 Expr *OrigCallee,
11188 Expr *First,
11189 Expr *Second) {
11190 Expr *Callee = OrigCallee->IgnoreParenCasts();
11191 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011192
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011193 if (First->getObjectKind() == OK_ObjCProperty) {
11194 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11195 if (BinaryOperator::isAssignmentOp(Opc))
11196 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11197 First, Second);
11198 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11199 if (Result.isInvalid())
11200 return ExprError();
11201 First = Result.get();
11202 }
11203
11204 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11205 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11206 if (Result.isInvalid())
11207 return ExprError();
11208 Second = Result.get();
11209 }
11210
Douglas Gregora16548e2009-08-11 05:31:07 +000011211 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011212 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011213 if (!First->getType()->isOverloadableType() &&
11214 !Second->getType()->isOverloadableType())
11215 return getSema().CreateBuiltinArraySubscriptExpr(First,
11216 Callee->getLocStart(),
11217 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011218 } else if (Op == OO_Arrow) {
11219 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011220 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11221 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011222 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011223 // The argument is not of overloadable type, so try to create a
11224 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011225 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011226 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011227
John McCallb268a282010-08-23 23:25:46 +000011228 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011229 }
11230 } else {
John McCallb268a282010-08-23 23:25:46 +000011231 if (!First->getType()->isOverloadableType() &&
11232 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011233 // Neither of the arguments is an overloadable type, so try to
11234 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011235 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011236 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011237 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011238 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011240
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011241 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011242 }
11243 }
Mike Stump11289f42009-09-09 15:08:12 +000011244
11245 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011246 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011247 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011248
John McCallb268a282010-08-23 23:25:46 +000011249 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011250 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011251 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011252 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011253 // If we've resolved this to a particular non-member function, just call
11254 // that function. If we resolved it to a member function,
11255 // CreateOverloaded* will find that function for us.
11256 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11257 if (!isa<CXXMethodDecl>(ND))
11258 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011259 }
Mike Stump11289f42009-09-09 15:08:12 +000011260
Douglas Gregora16548e2009-08-11 05:31:07 +000011261 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011262 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011263 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011264
Douglas Gregora16548e2009-08-11 05:31:07 +000011265 // Create the overloaded operator invocation for unary operators.
11266 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011267 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011268 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011269 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011270 }
Mike Stump11289f42009-09-09 15:08:12 +000011271
Douglas Gregore9d62932011-07-15 16:25:15 +000011272 if (Op == OO_Subscript) {
11273 SourceLocation LBrace;
11274 SourceLocation RBrace;
11275
11276 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011277 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011278 LBrace = SourceLocation::getFromRawEncoding(
11279 NameLoc.CXXOperatorName.BeginOpNameLoc);
11280 RBrace = SourceLocation::getFromRawEncoding(
11281 NameLoc.CXXOperatorName.EndOpNameLoc);
11282 } else {
11283 LBrace = Callee->getLocStart();
11284 RBrace = OpLoc;
11285 }
11286
11287 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11288 First, Second);
11289 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011290
Douglas Gregora16548e2009-08-11 05:31:07 +000011291 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011292 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011293 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011294 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11295 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011297
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011298 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011299}
Mike Stump11289f42009-09-09 15:08:12 +000011300
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011301template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011302ExprResult
John McCallb268a282010-08-23 23:25:46 +000011303TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011304 SourceLocation OperatorLoc,
11305 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011306 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011307 TypeSourceInfo *ScopeType,
11308 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011309 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011310 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011311 QualType BaseType = Base->getType();
11312 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011313 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011314 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011315 !BaseType->getAs<PointerType>()->getPointeeType()
11316 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011317 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011318 return SemaRef.BuildPseudoDestructorExpr(
11319 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11320 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011321 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011322
Douglas Gregor678f90d2010-02-25 01:56:36 +000011323 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011324 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11325 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11326 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11327 NameInfo.setNamedTypeInfo(DestroyedType);
11328
Richard Smith8e4a3862012-05-15 06:15:11 +000011329 // The scope type is now known to be a valid nested name specifier
11330 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011331 if (ScopeType) {
11332 if (!ScopeType->getType()->getAs<TagType>()) {
11333 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11334 diag::err_expected_class_or_namespace)
11335 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11336 return ExprError();
11337 }
11338 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11339 CCLoc);
11340 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011341
Abramo Bagnara7945c982012-01-27 09:46:47 +000011342 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011343 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011344 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011345 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011346 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011347 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011348 /*TemplateArgs*/ nullptr,
11349 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011350}
11351
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011352template<typename Derived>
11353StmtResult
11354TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011355 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011356 CapturedDecl *CD = S->getCapturedDecl();
11357 unsigned NumParams = CD->getNumParams();
11358 unsigned ContextParamPos = CD->getContextParamPosition();
11359 SmallVector<Sema::CapturedParamNameType, 4> Params;
11360 for (unsigned I = 0; I < NumParams; ++I) {
11361 if (I != ContextParamPos) {
11362 Params.push_back(
11363 std::make_pair(
11364 CD->getParam(I)->getName(),
11365 getDerived().TransformType(CD->getParam(I)->getType())));
11366 } else {
11367 Params.push_back(std::make_pair(StringRef(), QualType()));
11368 }
11369 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011370 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011371 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011372 StmtResult Body;
11373 {
11374 Sema::CompoundScopeRAII CompoundScope(getSema());
11375 Body = getDerived().TransformStmt(S->getCapturedStmt());
11376 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011377
11378 if (Body.isInvalid()) {
11379 getSema().ActOnCapturedRegionError();
11380 return StmtError();
11381 }
11382
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011383 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011384}
11385
Douglas Gregord6ff3322009-08-04 16:50:30 +000011386} // end namespace clang
11387
Hans Wennborg59dbe862015-09-29 20:56:43 +000011388#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H